Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi dear's
i design a treeview which show my information,
i want when name node="sample" it's automaticaly disabled,
how i can??
sincerely yours
Posted
Updated 20-May-12 22:01pm
v3

AFAIK, you can't do it automatically - there is no "Node added" event you can handle, so you would have to check manually every time you add a node.
The other problem is that TreeNodes doen't have an Enabled property, so you can't disable it without doing some slightly complicated processing.

What are you trying to achieve, that you think this would help? There may be a better solution.
 
Share this answer
 
Although there is no "enabled" property, you can simulate it by graying out the node and avoiding that anyone can click on it. Maybe this could work:
C#
private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
  if (Color.Gray == e.Node.ForeColor)
    e.Cancel = true;
}

private void Form1_Load(object sender, EventArgs e)
{
  foreach (TreeNode node in treeView1.Nodes)
    if (node.Text == "sample")
      node.ForeColor = Color.Gray;
}
 
Share this answer
 
v2
Comments
VJ Reddy 21-May-12 4:47am    
Good answer. 5!
JF2015 21-May-12 4:48am    
Thank you very much!
Ana Valero 24-Nov-14 4:23am    
Works perfectly!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900