In the above image "ug(User Group)" is a row in a checkedlistbox with enabled property to false. How to uncheck "ug(User Group)" in disabled state.
You can easily use
checkedListBox1.SetItemChecked(2, false);
or
checkedListBox1.SetItemCheckState(2, CheckState.Unhecked);
The Enabled
property of the CheckedListBox
has no impact on the check state of the items or those two methods.
MSDN links:
UPDATE: Disabling a single item in the CheckedListBox
instead of disabling the whole control is not possible out of the box.
If you want to prevent the user from changing the check state of one special item, you need to subscribe to the ItemCheck
event of the CheckedListBox
:
checkedListBox1.ItemCheck += (sender, e) =>
{
if (e.Index == 2)
e.NewValue = CheckState.Unchecked;
}
This event is fired before the check state of the item changed. e
is an ItemCheckEventArgs
that contains the item's Index
, its current check state ( CurrentValue
) and the check state it shall have afterwards ( NewValue
).
So setting e.NewValue = CheckState.Unchecked
prevents the item from being checked again by the user.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.