如何禁用一个的CheckedListBox一个复选框? [英] How to disable a checkbox in a checkedlistbox?
问题描述
我有一个检查列表框中的一些项目,我想禁用它第一个项目的复选框。结果
即我想在的CheckedListBox禁用的第一个项目,是因为我想告诉用户视觉上的选项不可用。
I have some items in a checked list box, I want to disable the checkbox of first item in it.
i.e. I want to disable the first item in the CheckedListBox, because I want to tell the user visually that option is not available.
推荐答案
综合以上部分答案2为我工作很好。
添加您的物品清单与
Combining 2 of the above partial answers worked great for me. Add your items to the list with:
myCheckedListBox.Items.Add(myItem, myState);
在哪里myState是CheckState.Indeterminate对于应禁用物品。
然后添加事件处理程序,以保持这些项目被更改:
Where myState is CheckState.Indeterminate for items that should be disabled. Then add an event handler to keep those items from being changed:
myCheckedListBox.ItemCheck += (s, e) => { if (e.CurrentValue == CheckState.Indeterminate) e.NewValue = CheckState.Indeterminate; };
这不允许使用'不确定'在此列表中其正常目的,但它确实给一个看起来非常相似,什么人会期望一个禁用的项目,它提供了正确的行为!
This does not allow you to use 'Indeterminate' in this list for its normal purpose but it does give a look very similar to what one would expect for a disabled item and it provides the correct behavior!
这篇关于如何禁用一个的CheckedListBox一个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!