Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to retrieve the node name according to the treeDirectory index when the Enter key is pressed
Alternative: event name at node change


What I have tried:

private void treeDirectory_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {                
                int idxNode = treeDirectory.SelectedNode.Index;
                
                //How read the text of node ?


                //on Mousedouble click is possible
                //string path = pathDirectory + e.Node.FullPath + "\\";                        

                //Alternative: event name at node change
               
                //the variable  add the text of current node
                //but when node change must be erase --> pathNode = ""
                
                pathNode += treeDirectory.SelectedNode.Text + "\\";
                string path = pathDirectory + pathNode;

                //example 
                //1 - select download pathNode = "<path>\\Download\\;
                //2 - select pictures
                //3 - select A = "<path>\\Download\\A\\;</pre
                //4 - change node and select Documents 
                //I have to intercept the node change event
                ......
            }
        }
Posted
Updated 2-Oct-20 5:02am

You will have to go back to where you got the TreeDirectory control code from - there are dozens of controls available with that name (Google[^]) and they all work differently. There is no standard control of that name, and we have no idea which you might have found, or if you wrote it yourself!

Sorry, but we can't help you with this.
 
Share this answer
 
I solved it like this by calling the method
treeDirectory.SelectedNode.FullPath


treeDirectory component is part of System.Windows.Forms.TreeView

private void treeDirectory_KeyPress(object sender, KeyPressEventArgs e)
       {
           if (e.KeyChar == 13)
           {
               //where pathDirectory is variable from other control
               string path = pathDirectory + treeDirectory.SelectedNode.FullPath + "\\";
               <other code>
           }
       }


note: as I declare the question solved ? 
 
Share this answer
 
Comments
BillWoodruff 3-Oct-20 0:36am    
Next time tell us what the Control is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900