Reputation: 2496
I have a treeview with multiple nodes with the same text and quite nested inside.
I wonder how to select node and get exact path of it by index not text
Like selected is
treeview.nodes[3].nodes[2].nodes[7]
the path is 3/2/7
Upvotes: 0
Views: 1160
Reputation: 609
Here is a sample how it should work to get a string
path from your Treeview
.
TreeNode tmp = treeview.nodes[3].nodes[2].nodes[7];
string path = String.Empty;
while(tmp != null)
{
path.insert(0, "/" tmp.Index);
tmp = tmp.Parent;
}
path.Remove(0,1); // remove first '/' sign
Not fully tested this sample, but I should be hint for you. Hope that will solve your problem, if not please add further details to your question.
Upvotes: 2