0

I have a treenode which i create dynamically as described below: ->UK,->India ->Delhi ->Mumbai ->USA ->Russia I need to change the color of the node when i click on the node. As for eg if i click on delhi delhi should be highlighted, if russia then russia. etc I call the the same when i click on the node

Saiyam
  • 138
  • 2
  • 11

1 Answers1

0

You can use NodeMouseClick event to set the background color of the selected Node.

Define a class level TreeNode member

TreeNode node = null;

And use the logic given below,

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
    if (null != node)
     {
         //Reset the color when selected node changes
         node.BackColor = Color.White;
     }

     //Set the currently selected node color
     e.Node.BackColor = Color.Green;

     node = e.Node;
 }
Kurubaran
  • 8,696
  • 5
  • 43
  • 65