TreeNode.FullPath 属性

定义

设置从根树节点到当前树节点的路径。

public:
 property System::String ^ FullPath { System::String ^ get(); };
public string FullPath { get; }
[System.ComponentModel.Browsable(false)]
public string FullPath { get; }
member this.FullPath : string
[<System.ComponentModel.Browsable(false)>]
member this.FullPath : string
Public ReadOnly Property FullPath As String

属性值

String

从根树节点到当前树节点的路径。

属性

例外

此节点未包含在 TreeView 中。

示例

下面的代码示例设置一个属性,PathSeparator并显示包含在TreeNodeCollection其中的SelectedNode子树节点TreeView数。 树视图控件中子树节点到树节点总数的百分比也显示。 此示例要求你有一个具有一ButtonForm对象,并且TreeView具有多个TreeNode对象的控件TreeNodeCollection (最好具有三个或更多个级别) 。

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( String::Concat( "The '", myTreeView->SelectedNode->FullPath, "' node has ", myNodeCount, " child nodes.\nThat is ", String::Format( "{0:###.##}", myChildPercentage ), "% of the total tree nodes in the tree view control." ) );
}
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.");
}
Private Sub myButton_Click(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles myButton.Click
   ' Set the tree 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

注解

路径包含必须导航到以从根树节点开始访问此树节点的所有树节点的标签。 节点标签由包含此节点的TreeView控件属性中指定的PathSeparator分隔符字符分隔。 例如,如果名为“Location”的树视图控件的分隔符字符设置为反斜杠字符, (\) ,则 FullPath 属性值为“Country\Region\State”。

适用于

另请参阅