I am trying to make a directory tree in c# using a tree view.And i want the node to expand only when any node is double clicked.For doubleclick event i used the following code:
this.treeView1.DoubleClick +=new System.EventHandler(treeView1_DoubleClick);
private void treeView1_DoubleClick(object sender, EventArgs e){
if (treeView1.SelectedNode !=null){
//expand the selected node
}
}
but the problem is this event works if i click in any other area of the control
if i single click a treenode, the node gets selected and now if i double clicked in any other part of the control still it will works
Is there any way to avoid this
And is there any way that i can deselect any selected node

some questions about treeview!!
Andrei Asayonak
Ok i want to explain my problem in detail.I have made an application with a text editor and a directory viewer. Some portion of the form is occupied by a directory viewer where user can select the files.What i want to do is that whenever a user double clicked any file from the directory viewer i want to open that file in my text editor.How can i use the doubleclick event to know which file is selected
Med Bouchenafa
I would also encourage you just to let the TreeView use its default collapsing / expanding rules as this is most familiar to users.