c# - No overload for '...' matches delegate 'System.Windows.Forms.ItemCheckEventHandler' -
after reading this question, has become apparent me writing event incorrectly. however, have no idea how going able re-write have written using object sender. event adds text selected checkboxes two-dimensional list (report), , order in report must same order of selected checkboxes. also, no more 2 checkboxes can selected @ time. here event:
void checkedlistbox_itemcheck(checkedlistbox chkdlstbx, itemcheckeventargs e) { int index = convert.toint32(chkdlstbx.tag); if ((chkdlstbx.checkeditems.count == 0) && (e.currentvalue == checkstate.unchecked)) { var.report[index].add(chkdlstbx.text); } if ((chkdlstbx.checkeditems.count == 1) && (e.currentvalue == checkstate.checked)) { var.report[index].removeat(0); } if ((chkdlstbx.checkeditems.count == 1) && (e.currentvalue == checkstate.unchecked)) { if (chkdlstbx.selectedindex < chkdlstbx.checkedindices[0]) { var.report[index].insert(0, chkdlstbx.text); } else { var.report[index].add(chkdlstbx.text); } } if ((chkdlstbx.checkeditems.count == 2) && (e.currentvalue == checkstate.checked)) { if (chkdlstbx.selectedindex == chkdlstbx.checkedindices[0]) { var.report[index].removeat(0); } else { var.report[index].removeat(1); } } if ((chkdlstbx.checkeditems.count == 2) && (e.currentvalue == checkstate.unchecked)) { e.newvalue = checkstate.unchecked; } updatereport(); }
it being called line:
chkdlstbx.itemcheck += new itemcheckeventhandler(checkedlistbox_itemcheck);
if me re-write event using object, that'd awesome. i'm not sure how else go solving problem!
this should suffice:
void checkedlistbox_itemcheck(object sender, itemcheckeventargs e) { checkedlistbox chkdlstbx = sender checkedlistbox; if (chkdlstbx == null) { throw new invalidargumentexception(); } .... }
Comments
Post a Comment