Treeview Control in WindowsForms Application


This is the example for the Treeview Control and its some events which are usefull like AfterSelect and DoubleClick of mouse.Generally we saw TreeView type in our own systems like when you see folder you can see what files it contains on the left side when we search.

TreeView Control in Windows Forms Application.

Recently I saw a post many times regarding the treeview control how to show the selected node text, which event to use and how to double-click which event it fires. So here is the example for treeview.

Steps to do:
1) Take a new form and place the treeview control.
2) Select the dock property of the control and make it fill so it covers all the form empty space.
3) Now add the items in the structural way as in the below images. You use edit items in the smart tag of the treeview control (see below image).
4) Now goto the event and select AfterSelect event of the treeview which fires after selecting the node in the tree.
5) Now we will display the text of the node when it selects by using the below code


MessageBox.Show(treeView1.SelectedNode.Text.ToUpper());

6) Now you can check for the click event and doubleclick event also like

private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show(treeView1.SelectedNode.Text.ToUpper()+"this is coming on double click of node.");
}


7) For expanding all the nodes in the starting itself you can use

private void treeview_Load(object sender, EventArgs e)
{
treeView1.ExpandAll();
}


Here this is small example you can try the same example like in the windows.


Attachments

  • TreeView in WindowsForms (44117-12316-TreeView-WindowsForms.rar)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: