Get selected tree node item full path in C# (WinForms)

Yolgezer picture Yolgezer · Jan 29, 2014 · Viewed 11.3k times · Source

I have a TreeView component and content of it like this:

MainLine  
  + SubLine1 
  + SUbline2
  + Subline3
  + Subline4
  + Subline5
  - Subline6
      SublineDetail1
      **SublineDetail2**
      SublineDetail3

Assume that SublineDetail2 is selected and I want to get full path of it as string to a textbox just like this "(1.6.2)".

How can I do that?

Answer

user3244607 picture user3244607 · Feb 7, 2014
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
    TreeNode CurrentNode= e.Node;
    string fullpath= CurrentNode.FullPath;
    MessageBox.Show(fullpath);
}