TreeView.PathSeparator Property

 

Gets or sets the delimiter string that the tree node path uses.

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

public string PathSeparator { get; set; }

Property Value

Type: System.String

The delimiter string that the tree node TreeNode.FullPath property uses. The default is the backslash character (\).

The tree node path consists of a set of tree node labels separated by the PathSeparator delimiter strings. The labels range from the root tree node to the tree node that you want.

The following code example sets the PathSeparator property of a TreeView and displays the number of child tree nodes that is 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
Show: