Newbie: How to get TreeView node from FullPath?

D

deko

If I know the FullPath to a node in a TreeView, how do I insert a new node
under that node?

I need to run some code on DoubleClick of a node to get the value of the new
node I want to add to that node. Then, I need to reference that node in a
separate method so I can add the new node (that is, add the new node to the
Node that was double clicked).

In pseudo code, it might look like this:

private string m_nodePath = "";

private void tvwMyTreeView_NodeMouseDoubleClick(object sender,
TreeNodeMouseClickEventArgs e)
{
m_nodePath = tvwConfigurations.SelectedNode.FullPath;
callSomeMethodHereToGetNewNodeValue();
}

private void SomeOtherMethodToInsertNewNodeValue()
{
TreeNode myNewNode = tvwMyTreeView.Nodes(m_nodePath).Add(newNodeValue);
//How do I reference the node by FullPath?
}

Thanks in advance.
 
B

Bob

Hi,
I might be missing the point here but why don't you use the double clicked
node instead of the path. ( You said they double click on the node of
interest.) i.e. Don't worry about where the node is just reference it add
the new node to it.
In the DoubleClick event handler something like:
TreeNode t = ctype(sender,TreeNode);
SomeOtherMethodToInsertNewNodeValue(t);

private void SomeOtherMethodToInsertNewNodeValue(ref TreeNode t)//passing
in selected node
{
String s = DoSomethingUseful();
TreeNode myNewNode = new TreeNode(s);//Just setting the label as an example
t.Add(myNewNode);
HTH
Bob
 
D

deko

I might be missing the point here but why don't you use the double clicked
node instead of the path. ( You said they double click on the node of
interest.) i.e. Don't worry about where the node is just reference it add
the new node to it.
In the DoubleClick event handler something like:
TreeNode t = ctype(sender,TreeNode);
SomeOtherMethodToInsertNewNodeValue(t);

private void SomeOtherMethodToInsertNewNodeValue(ref TreeNode t)//passing
in selected node
TreeNode myNewNode = new TreeNode(s);//Just setting the label as an
example
t.Add(myNewNode);

You are 100% correct. I need to remember C# is OO. Once I have a reference
to the object I can pass that around and access the properties as needed.

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top