How to disable a checkbox in a checkedlistbox?

后端 未结 11 720
遥遥无期
遥遥无期 2020-12-03 10:46

I have some items in a CheckedListBox, I want to disable the CheckBox of first item in it.
i.e. I want to disable the first item in the C

相关标签:
11条回答
  • 2020-12-03 11:12

    I think an alternative solution, is using Telerik components.

    A RadListControl can give you that option:

    enter image description here

    0 讨论(0)
  • 2020-12-03 11:17

    I know it has been a while, but I found this in my search for a list box and thought I would add it to the discussion.

    If you have a listbox and want to disable all of the checkboxes so they cannot be clicked, but not disable the control so the user can still scroll etc. you can do this:

    listbox.SelectionMode = SelectionMode.None
    
    0 讨论(0)
  • 2020-12-03 11:20

    Combining 2 of the above partial answers worked great for me. Add your items to the list with:

    myCheckedListBox.Items.Add(myItem, myState);
    

    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!

    0 讨论(0)
  • 2020-12-03 11:21

    To disable any particular item use following:

    checkedListBox1.SetItemCheckState(0, CheckState.Indeterminate);
    

    SetItemCheckState takes index of item and CheckState Enum Indeterminate is used to show shaded appearance

    0 讨论(0)
  • 2020-12-03 11:24

    This works for me:

    checkedListBox1.SelectionMode = SelectionMode.None;
    

    Which means no items can be selected

    None: No items can be selected.

    For more info, you can check it here: SelectionMode Enumeration.

    0 讨论(0)
提交回复
热议问题