Reputation: 13
I have Checkboxes
in my ListView
control and set to True.
Further, I add items in the ListView
one by one. It is not bound to a DataSet
/ DataTable
.
At time, I am adding items with Checkbox.Checked = true
in my ListView
.
i.e. listview1.Items(i).Checked = True
For some of the items after setting up Checked property to true, I want to disable the Checkbox
so that user cannot uncheck the CheckBox
.
I am trying to figure out options on how to disable the Checkboxes
, but haven't found a solution yet.
Thanks in advance.
Upvotes: 1
Views: 7856
Reputation: 31
For me, this works: Handle ListView.ItemCheck Event.
Use the following code there:
private void listView1_BeforeCheck(object sender, ItemCheckEventArgs e)
{
if (!CheckEnabled(e)) // check somehow if clicked item is disabled
e.NewValue = e.CurrentValue;
}
Upvotes: 3
Reputation: 3313
This is a 3rd party control, Better ListView, but it may interest you. It supports custom check box appearances and hiding (the last two items have check boxes hidden):
To hide a check box on a specific item, simple use:
betterListView.Items[0].CheckBoxAppearance = BetterListViewCheckBoxAppearance.Hide;
Normal usage of check boxes is the same as in .NET ListView, you can have two-state or three-state check boxes or even radio buttons...
Upvotes: 0