TreeNode.FullPath 属性

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public ReadOnly Property FullPath As String
用法
Dim instance As TreeNode
Dim value As String

value = instance.FullPath
public string FullPath { get; }
public:
property String^ FullPath {
    String^ get ();
}
/** @property */
public String get_FullPath ()
public function get FullPath () : String

属性值

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

异常

异常类型 条件

InvalidOperationException

此节点未包含在 TreeView 中。

备注

路径从根树节点开始,包括要达到该树节点而必须浏览的所有树节点的标签。分隔节点标签的分隔符在包含该节点的 TreeView 控件的 PathSeparator 属性中指定。例如,如果名为“Location”的树视图控件的分隔符设置为反斜杠字符 (\),FullPath 属性值就为“Country\Region\State”。

示例

下面的代码示例设置 TreeViewPathSeparator 属性,并显示 SelectedNodeTreeNodeCollection 中包含的子树节点数。还显示树视图控件中子树节点占全部树节点的百分比。本示例要求有一个包含 ButtonForm 和一个包含 TreeNodeCollectionTreeView 控件,该集合包含若干个 TreeNode 对象(最好具有三级或三级以上)。

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
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.");
}
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( 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 tre view's PathSeparator property.
    myTreeView.set_PathSeparator(".");
    // Get the count of the child tree nodes contained in the SelectedNode.
    int myNodeCount = myTreeView.get_SelectedNode().GetNodeCount(true);
    System.Decimal myChildPercentage =
        Decimal.Multiply(Decimal.Divide(new Decimal(myNodeCount),
        new Decimal(myTreeView.GetNodeCount(true))), new Decimal(100));
    // Display the tree node path and the number of child nodes it and the
    // tree view have.
    MessageBox.Show("The '" + myTreeView.get_SelectedNode().get_FullPath()
        + "' node has " + ((Int32)myNodeCount).ToString()
        + " child nodes.\nThat is " + String.Format("{0:###.##}",
        myChildPercentage)
        + "% of the total tree nodes in the tree view control.");
} //myButton_Click

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

TreeNode 类
TreeNode 成员
System.Windows.Forms 命名空间
PathSeparator