Reputation: 2726
I want to disable user for changing state of check box in TreeView after all nodes and childnodes are checke. This is the way how I check all items in treeview:
private void CheckItems()
{
foreach (TreeNode node in tvSastavnica.Nodes)
{
node.Checked = true;
CheckChildren(node, true);
}
}
private void CheckChildren(TreeNode rootNode, bool isChecked)
{
foreach (TreeNode node in rootNode.Nodes)
{
CheckChildren(node, isChecked);
node.Checked = isChecked;
}
}
Now I want to grey or somehow lock checkboxes to prevent changing state. Is it possible?
Upvotes: 0
Views: 1045
Reputation: 1079
You can do this with the BeforeCheck and AfterCheck events:
private void tvSastavnica_BeforeCheck(object sender, TreeViewCancelEventArgs e)
{
e.Cancel = true;
}
Or:
private void tvSastavnica_AfterCheck(object sender, TreeViewCancelEventArgs e)
{
e.Cancel = true;
}
Upvotes: 1