disabling/greying a treeview node
-
In a C# Windows Form, I have a treeview/listview pair that behaves like Windows Explorer, displaying drives, folders and files... I want to display certain treeview nodes as disabled or greyed... Can someone tell me how this can be done? thanks very much.
-
In a C# Windows Form, I have a treeview/listview pair that behaves like Windows Explorer, displaying drives, folders and files... I want to display certain treeview nodes as disabled or greyed... Can someone tell me how this can be done? thanks very much.
A simple solution that may do what you want is to simply set the
ForeColor
of the node you want greyed toColor.Gray
orColor.LightGray
. You can then handle theBeforeSelect
event of the treeview and check for the fore color, if it isColor.Gray
orColor.LightGray
, depending on which you choose, set the Cancel property of theTreeViewCancelEventArgs
to true:private void treeView1_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) { if(e.Node.ForeColor == Color.Gray) { e.Cancel = true; } }
Hope this is useful
-
A simple solution that may do what you want is to simply set the
ForeColor
of the node you want greyed toColor.Gray
orColor.LightGray
. You can then handle theBeforeSelect
event of the treeview and check for the fore color, if it isColor.Gray
orColor.LightGray
, depending on which you choose, set the Cancel property of theTreeViewCancelEventArgs
to true:private void treeView1_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) { if(e.Node.ForeColor == Color.Gray) { e.Cancel = true; } }
Hope this is useful