TreeNode.FullPath Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the path from the root tree node to the current tree node.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public string FullPath { get; }

Property Value

Type: System.String

The path from the root tree node to the current tree node.

Exception Condition

The node is not contained in a TreeView.

The path consists of the labels of all the tree nodes that must be navigated to reach this tree node, starting at the root tree node. The node labels are separated by the delimiter character specified in the PathSeparator property of the TreeView control that contains this node. For example, if the delimiter character of the tree view control named "Location" is set to the backslash character, (\), the FullPath property value is "Country\Region\State".

The following code example sets the PathSeparator property of a TreeView and displays the number of child tree nodes that are contained in the TreeNodeCollection of the SelectedNode. The percentage of child tree node to total tree nodes in the tree view control is also displayed. This example requires that you have a Form with a Button, and a TreeView control with a TreeNodeCollection that has several TreeNode objects (preferably with three or more levels).

private void myButton_Click(object sender, System.EventArgs e)
   // Set the tree view's PathSeparator property.
   myTreeView.PathSeparator = ".";

   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView.SelectedNode.GetNodeCount(true);
   decimal myChildPercentage = ((decimal)myNodeCount/
     (decimal)myTreeView.GetNodeCount(true)) * 100;

   // Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox.Show("The '" + myTreeView.SelectedNode.FullPath + "' node has " 
     + myNodeCount.ToString() + " child nodes.\nThat is " 
     + string.Format("{0:###.##}", myChildPercentage) 
     + "% of the total tree nodes in the tree view control.");

.NET Framework
Available since 1.1
Return to top