i have used the treeview control to list out the contents of a directory . I want to add an event when the user double clicks any of the nodes. For example when the uder double clicks the any of the text file i want to open it. The problem is that i havent any idea of how to do that. How can i do something when user double clicks any of the node.

problem in adding an event in the treeview
Akwest
Sigme, sorry, I pasted the wrong event handler. Use this one.
.myTreeview.DoubleClick +=new System.EventHandler(myTreeview_DoubleClick);MikeD
this
mattyo
I use a Before and After Select event to change the color of the selected node.
I don't use a double click event, but I also use a MouseClick event to dropdown a menu when the user RightClicks a selected node. You may want to go to that if you don't like the double click event.
The selected node looses it shading if you click elswhere on the form, but it is still selected. That is why I had to go to the before and after to keep it hi-lighted in a different color.
You inspect the selected node this way in your double click event.
if (myTreeview.SelectedNode !=null){
MessageBox.Show("you doubleclicked on:"+myTreeview.SelectedNode.Text)
}
MikeD
MitkoB
markybark
cuz if i click any node once and then double click anywhere else in the control area it still works as the selected node still remains selected . I want to deselect all the selected nodes if the user selects on the other areas of the control
how can i do that
anyway something is better than nothing
SydneyGentleman
Hi Sigme,
.myTreview.DoubleClick += new System.EventHandler(this.myTreeView_DoubleClick);Here is the designer portion that adds the event.
this
then add the myTreeView_DoubleClick method
private
void myTreeview_DoubleClick(object sender, EventArgs e){// what ever you want to do with the selected node
myTreeview.SelectedNode.Text="Howdy"
}
MikeD
serimc
Mike D
private void myTreeview_DoubleClick(object sender, EventArgs e){
// what ever you want to do with the selected node
myTreeview.SelectedNode.Text="Howdy"
Daniel Miller
thanks but still there is a problem because i used the code you gave but when i build the solution i get the following error message
Cannot implicitly convert type 'System.Windows.Forms.TreeViewCancelEventHandler' to 'System.EventHandler'
please help me with this. Is there any alternative method to respond when the user double clicks only the node not the treeview area
Nikolaus Brennig
You may be able to set the selection during the double click event.
Look up Drag and Drop on a treeview. It uses the mouse position to locate the selection in the treeview.
I have not done any Drag and Drop yet, so I can't help,
MikeD