Export (0) Print
Expand All

TreeView.PathSeparator Property

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

[Visual Basic]
Public Property PathSeparator As String
[C#]
public string PathSeparator {get; set;}
[C++]
public: __property String* get_PathSeparator();
public: __property void set_PathSeparator(String*);
[JScript]
public function get PathSeparator() : String;
public function set PathSeparator(String);

Property Value

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

Remarks

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.

Example

[Visual Basic, C#, C++] The following example set the PathSeparator proprety of a TreeView and displays the number of child tree nodes 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 assumes 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).

[Visual Basic] 
Private Sub myButton_Click(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles myButton.Click
   ' Set the tre view's PathSeparator property.
   myTreeView.PathSeparator = "."

   ' Get the count of the child tree nodes contained in the SelectedNode.
   Dim myNodeCount As Integer = myTreeView.SelectedNode.GetNodeCount(True)
   Dim myChildPercentage As Decimal = CDec(myNodeCount) / _
      CDec(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." + Microsoft.VisualBasic.ControlChars.Lf _
      + "That is " + String.Format("{0:###.##}", myChildPercentage) _
      + "% of the total tree nodes in the tree view control."))
End Sub

[C#] 
private void myButton_Click(object sender, System.EventArgs e)
{
   // Set the tre 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.");
}

[C++] 
private:
    void myButton_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
        // Set the tre view's PathSeparator property.
        myTreeView->PathSeparator = S".";

        // 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(String::Concat(S"The '", myTreeView->SelectedNode->FullPath,
            S"' node has ", __box(myNodeCount), S" child nodes.\nThat is ",
            String::Format(S"{0:###.##}", __box(myChildPercentage)),
            S"% of the total tree nodes in the tree view control."));
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

TreeView Class | TreeView Members | System.Windows.Forms Namespace | FullPath

Show:
© 2014 Microsoft