ツリー ノード コレクションを反復処理するために使用できる列挙子を返します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
'宣言
Public Function GetEnumerator As IEnumerator
'使用
Dim instance As TreeNodeCollection
Dim returnValue As IEnumerator
returnValue = instance.GetEnumerator
public IEnumerator GetEnumerator ()
public:
virtual IEnumerator^ GetEnumerator () sealed
public final IEnumerator GetEnumerator ()
public final function GetEnumerator () : IEnumerator
戻り値
ツリー ノードのコレクションを表す IEnumerator。
使用例
指定した TreeNode が TreeNodeCollection 内にあるかどうかを確認した後で、そのコレクションを列挙するコード例を次に示します。この例は Form に TreeView が配置され、そこに、myTreeNode2
という名前の TreeNode を含む TreeNodeCollection が割り当てられていることを前提としています。
Private Sub EnumerateTreeNodes()
Dim myNodeCollection As TreeNodeCollection = myTreeView.Nodes
' Check for a node in the collection.
If myNodeCollection.Contains(myTreeNode2) Then
myLabel.Text += "Node2 is at index: " + myNodeCollection.IndexOf(myTreeNode2)
End If
myLabel.Text += ControlChars.Cr + ControlChars.Cr + _
"Elements of the TreeNodeCollection:" + ControlChars.Cr
' Create an enumerator for the collection.
Dim myEnumerator As IEnumerator = myNodeCollection.GetEnumerator()
While myEnumerator.MoveNext()
myLabel.Text += CType(myEnumerator.Current, TreeNode).Text + ControlChars.Cr
End While
End Sub
private void EnumerateTreeNodes()
{
TreeNodeCollection myNodeCollection = myTreeView.Nodes;
// Check for a node in the collection.
if (myNodeCollection.Contains(myTreeNode2))
{
myLabel.Text += "Node2 is at index: " + myNodeCollection.IndexOf(myTreeNode2);
}
myLabel.Text += "\n\nElements of the TreeNodeCollection:\n";
// Create an enumerator for the collection.
IEnumerator myEnumerator = myNodeCollection.GetEnumerator();
while(myEnumerator.MoveNext())
{
myLabel.Text += ((TreeNode)myEnumerator.Current).Text +"\n";
}
}
void EnumerateTreeNodes()
{
TreeNodeCollection^ myNodeCollection = myTreeView->Nodes;
// Check for a node in the collection.
if ( myNodeCollection->Contains( myTreeNode2 ) )
{
myLabel->Text = myLabel->Text + "Node2 is at index: " + myNodeCollection->IndexOf( myTreeNode2 );
}
myLabel->Text = myLabel->Text + "\n\nElements of the TreeNodeCollection:\n";
// Create an enumerator for the collection.
IEnumerator^ myEnumerator = myNodeCollection->GetEnumerator();
while ( myEnumerator->MoveNext() )
{
myLabel->Text = myLabel->Text + (dynamic_cast<TreeNode^>(myEnumerator->Current))->Text + "\n";
}
}
private void EnumerateTreeNodes()
{
TreeNodeCollection myNodeCollection = myTreeView.get_Nodes();
// Check for a node in the collection.
if (myNodeCollection.Contains(myTreeNode2)) {
myLabel.set_Text(myLabel.get_Text() + "Node2 is at index: "
+ myNodeCollection.IndexOf(myTreeNode2));
}
myLabel.set_Text(myLabel.get_Text()
+ "\n\nElements of the TreeNodeCollection:\n");
// Create an enumerator for the collection.
IEnumerator myEnumerator = myNodeCollection.GetEnumerator();
while (myEnumerator.MoveNext()) {
myLabel.set_Text(myLabel.get_Text()
+ ((TreeNode)myEnumerator.get_Current()).get_Text() + "\n");
}
} //EnumerateTreeNodes
プラットフォーム
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
参照
関連項目
TreeNodeCollection クラス
TreeNodeCollection メンバ
System.Windows.Forms 名前空間