Reprint Office: http://shancheng2007.blog.163.com/blog/static/496838952010111452015761/
No direct way to disable a node is found, so the node forecolor to be disabled is set to gray
Then, in the BeforeSelect of the TreeView, the Beforecheck event is judged by the node color, and if it is gray, the user is not selected for that node
The reference code is as follows
Using System.Drawing;
Disable First node
Treeview1.nodes[0]. ForeColor = Color.gray;
It can be done after the binding data is complete, or it can be specified during the binding process, looking at the individual and the requirements.
private void Treeview1_beforeselect (object sender, TreeViewCancelEventArgs e)
{
if (E.node! = null)
{
if (E.node.forecolor = = Color.gray)
{
E.cancel = true; Do not let select Disable node
}
}
}
private void Treeview1_beforecheck (object sender, TreeViewCancelEventArgs e)
{
if (E.node! = null)
{
if (E.node.forecolor = = Color.gray)
{
E.cancel = true; Do not let select Disable node
}
}
}
When processing a selection node
foreach (TreeNode c_tn in Tr_subdepdev.nodes)
{
if (c_tn. Checked && C_tn. ForeColor! = Color.gray)//Device node is selected
{
Here to deal with
}
}
So that we can achieve the basic purpose ~
How to disable a node in the TreeView in C # WinForm