TreeNode.GetNodeCount(Boolean) Methode

Definition

Gibt die Anzahl der untergeordneten Strukturknoten zurück.Returns the number of child tree nodes.

public:
 int GetNodeCount(bool includeSubTrees);
public int GetNodeCount (bool includeSubTrees);
member this.GetNodeCount : bool -> int
Public Function GetNodeCount (includeSubTrees As Boolean) As Integer

Parameter

includeSubTrees
Boolean

true, wenn die Gesamtanzahl alle Strukturknoten umfasst, die indirekt bei diesem Strukturknoten beginnen, andernfalls false.true if the resulting count includes all tree nodes indirectly rooted at this tree node; otherwise, false.

Gibt zurück

Die Anzahl der untergeordneten Strukturknoten, die der Nodes-Auflistung zugewiesen sind.The number of child tree nodes assigned to the Nodes collection.

Beispiele

Im folgenden Codebeispiel wird die PathSeparator TreeView -Eigenschaft eines festgelegt und die Anzahl der untergeordneten Struktur Knoten angezeigt TreeNodeCollection , die in der SelectedNodedes-Objekts enthalten sind.The following code example sets the PathSeparator property of a TreeView and displays the number of child tree nodes that are contained in the TreeNodeCollection of the SelectedNode. Der Prozentsatz des untergeordneten Struktur Knotens auf Gesamtstruktur Knoten im Strukturansicht-Steuerelement wird ebenfalls angezeigt.The percentage of child tree node to total tree nodes in the tree view control is also displayed. Für dieses Beispiel ist es erforderlich, Form dass ein Buttonmit einem und TreeView ein-Steuer TreeNodeCollection Element mit einem TreeNode vorhanden ist, das über mehrere-Objekte verfügt (vorzugsweise mit drei oder mehr Ebenen).This example requires that 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).

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

Gilt für:

Siehe auch