Sunday, 15 August 2010

winforms - Checked items in C# Listview -



winforms - Checked items in C# Listview -

i have listview command in c# application filled names , checkboxes select 1 or more value. apart clicking on checkboxes, user can click on name , become blue. want maintain functionality clicking on name shows more info , clicking on checkbox marks farther processing

i believed clicking on checkbox changes item.checked property , clicking on name changes item.selected seems no simple.

i have code counts checked items:

private void listview1_itemchecked(object sender, itemcheckedeventargs e) { foreach(listviewitem item in listview1.items) { if (item != null) { if (item.checked == true) n++; } } textbox1.text = n.tostring(); }

when user clicks checkboxes there proper number displayes when clicks name, checked number changes 1 if there still more checkboxes checked, wrong. when form , command load, n=1 if there no checkboxes checked.

what doing wrong?

edit: quick response , useful hints!

and i've discovered problem negligence forgot remove old code! :) @ first used multiple selection pick items, switched checkboxes still calling selectionchanged event , modifying textbox content

to number of checked items in listview control, utilize listview.checkeditems.count property.

example:

int numcheckeditems = mylistview.checkeditems.count;

or

textbox1.text = mylistview.checkeditems.count.tostring();

c# winforms listview

No comments:

Post a Comment