|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
Does anyone know how to grey out and disable an item in a checkedListBox so that the user cannot check that item. with regards James |
|
#2
|
|||
|
|||
|
I dont now just that :)
A, I do not now but do you now how to add value from rows,
to CheckedListBox like it's items ? Thansk |
|
#3
|
|||
|
|||
|
You can use the Enabled property
Example
CheckBoxList1.Items[1].Enabled = false; you can use the above code to disbale the items of a check box list |
|
#4
|
|||
|
|||
|
Quote:
This clearly wouldn't work in a WinForms CheckedListBox as CheckedListBox1.Items[1] is of type "object" which has no Enabled property. There's no built in way of doing it, but you can work around it with by adding the specific item with CheckState.Indeterminate. This "looks" like it's checked and disabled. However, as it isn't really disabled, you'll need to handle the ItemCheck event and stop the user from changing the checked state. |
|
#5
|
|||
|
|||
|
Disabling items in a checkedListBox
Here is some sample code that can be used in the ItemCheck event of a CheckedListBox to make items disable like...
try { if (e.Index == 0 && e.NewValue == CheckState.Checked) { if (chkListBoxCategoris.SelectedValue.ToString() == "All") { for (int i = 1; i < chkListBoxCategoris.Items.Count; i++) { chkListBoxCategoris.SetItemCheckState(i, CheckState.Indeterminate); } } } else if (chkListBoxCategoris.GetItemCheckState(0) == CheckState.Checked) { if (e.Index != 0 && checkFlag == false) { if (e.CurrentValue == CheckState.Indeterminate) { e.NewValue = e.CurrentValue; } } else if (e.Index == 0) { checkFlag = true; for (int i = 1; i < chkListBoxCategoris.Items.Count; i++) { chkListBoxCategoris.SetItemCheckState(i, CheckState.Unchecked); } checkFlag = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } Happy Coding... Gokulan V |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Disabling an item in a checkedListBox C# |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|