How to uncheck disabled checkedlistbox in c# winforms? -
in above image "ug(user group)" row in checkedlistbox enabled property false. how uncheck "ug(user group)" in disabled state.
you can use
checkedlistbox1.setitemchecked(2, false);
or
checkedlistbox1.setitemcheckstate(2, checkstate.unhecked);
the enabled
property of checkedlistbox
has no impact on check state of items or 2 methods.
msdn links:
update: disabling single item in checkedlistbox
instead of disabling whole control not possible out of box.
if want prevent user changing check state of 1 special item, need subscribe itemcheck
event of checkedlistbox
:
checkedlistbox1.itemcheck += (sender, e) => { if (e.index == 2) e.newvalue = checkstate.unchecked; }
this event fired before check state of item changed. e
itemcheckeventargs
contains item's index
, current check state (currentvalue
) , check state shall have afterwards (newvalue
).
so setting e.newvalue = checkstate.unchecked
prevents item being checked again user.