Visit

Wednesday, August 10, 2011

TreeView Node Click Event in CSharp (C#)


In TreeView We need to Do any operation when a node clicked or selected.We can't trigger an event with the name of Node. We have to do it by triggering Tree Views Event.In this example i am used 'NodeMouseClick' Event.

1. Add a TreeView Control to your Form.
2. Add the Needed Nodes .
3. Now Double Click on TreeViews 'NodeMouseClick' Event.

4. Now Compare with Node.Name or Node.Text in the Event.just see the Code below.


private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
// Compare By Node.Name
if (e.Node.Name == "NodeJava")
{
MessageBox.Show("JAVA");
}
//Or
// Compare By Node.Text
if (e.Node.Text == "C#")
{
MessageBox.Show("C#");
}
}


*'NodeJava' is the Node Name ..and 'C#' is the Node Text in my example Code.I am just checking and showing the result in a MessageBox.
Checkout and Do Comment Here..

1 comment: