.net - I want to show any selected item from CheckedListBox in a ListBox in C# -



.net - I want to show any selected item from CheckedListBox in a ListBox in C# -

i have windows form application contains 1 "checkedlistbox" named "chkbox1" , contains items (blue, red, green, yellow).

the form contains empty "listbox" named "lstbox1".

i want when check item "chkbox1" add together "lstbox1" , when unchecked "chkbox1" removed "lstbox1".

i think should utilize "itemchecked" event don't know how can observe if item checked or not , add together list.

this try:

private void chkbox1_itemcheck(object sender, itemcheckeventargs e) { if (chkbox1.checkeditems.count > 0) listbox1.items.add(chkbox1.items[e.index]); else if (chkbox1.checkeditems.count == 0) listbox1.items.remove(chkbox1.items[e.index]); }

but add together item when unchecked not when check it.

and try:

private void chkbox1_itemcheck(object sender, itemcheckeventargs e) { if (chkbox1.getitemchecked(e.index) == true) listbox1.items.add(chkbox1.items[e.index]); else if (chkbox1.getitemchecked(e.index) == false) listbox1.items.remove(chkbox1.items[e.index]); }

try this:

private void chkbox1_itemcheck(object sender, itemcheckeventargs e) { if (e.newvalue == checkstate .checked) { listbox1.items.add(chkbox1.items[e.index]); } else { listbox1.items.remove(chkbox1.items[e.index]); } }

c# .net winforms listbox

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -