次の方法で共有


TreeNode.GetNodeCount メソッド

子ツリー ノードの数を返します。

Public Function GetNodeCount( _
   ByVal includeSubTrees As Boolean _) As Integer
[C#]
public int GetNodeCount(boolincludeSubTrees);
[C++]
public: int GetNodeCount(boolincludeSubTrees);
[JScript]
public function GetNodeCount(
   includeSubTrees : Boolean) : int;

パラメータ

  • includeSubTrees
    対象となるツリー ノードを間接的なルートとするすべてのツリー ノードを結果の数に含める場合は true 。それ以外の場合は false

戻り値

Nodes コレクションに割り当てられている子ツリー ノードの数。

使用例

[Visual Basic, C#, C++] TreeViewPathSeparator プロパティを設定し、 SelectedNodeTreeNodeCollection に含まれている子ツリー ノードの数を表示する例を次に示します。ツリー ビュー コントロール内のすべてのツリー ノードに対する子ツリー ノードの割合も表示されます。この例は、 Button と、複数の TreeNode オブジェクト (3 レベル以上を推奨) を格納している TreeNodeCollection が設定された TreeView コントロールが配置された Form があることを前提にしています。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

TreeNode クラス | TreeNode メンバ | System.Windows.Forms 名前空間 | Nodes | TreeNodeCollection