英語で読む

次の方法で共有


TreeNode.FullPath プロパティ

定義

ルート ツリー ノードから現在のツリー ノードまでのパスを取得します。

C#
public string FullPath { get; }
C#
[System.ComponentModel.Browsable(false)]
public string FullPath { get; }

プロパティ値

ルート ツリー ノードから現在のツリー ノードまでのパス。

属性

例外

ノードが TreeView に含まれていません。

次のコード例では、 の プロパティをPathSeparatorTreeView設定し、 の にTreeNodeCollection含まれる子ツリー ノードの数をSelectedNode表示します。 ツリー ビュー コントロールのツリー ノードの合計に対する子ツリー ノードの割合も表示されます。 この例では、 を持FormButtonと、TreeView複数TreeNodeのオブジェクト (できれば 3 つ以上のレベルを持つ) を持つ コントロールTreeNodeCollectionが必要です。

C#
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.");
}

注釈

パスは、ルート ツリー ノードから開始して、このツリー ノードに到達するために移動する必要があるすべてのツリー ノードのラベルで構成されます。 ノード ラベルは、このノードを含むコントロールの TreeView プロパティで指定された区切り文字でPathSeparator区切られます。 たとえば、"Location" という名前のツリー ビュー コントロールの区切り文字が円記号 (\) FullPath に設定されている場合、プロパティの値は "Country\Region\State" になります。

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

こちらもご覧ください