コレクション内の指定されたツリー ノードのインデックスを返します。
Public Function IndexOf( _
ByVal node As TreeNode _) As Integer
[C#]
public int IndexOf(TreeNodenode);
[C++]
public: int IndexOf(TreeNode* node);
[JScript]
public function IndexOf(
node : TreeNode) : int;
パラメータ
- node
コレクション内で検索する TreeNode 。
戻り値
ツリー ノード コレクション内に項目が存在する場合は、その項目の 0 から始まるインデックス。それ以外の場合は -1。
使用例
[Visual Basic, C#, C++] 指定した TreeNode が TreeNodeCollection 内にあるかどうかを確認し、そのコレクションを列挙する例を次に示します。この例は、 myTreeNode2
という名前の TreeNode が格納された TreeNodeCollection がある、 TreeView が配置された Form があることを前提にしています。
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
[C#]
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";
}
}
[C++]
private:
void EnumerateTreeNodes() {
TreeNodeCollection* myNodeCollection = myTreeView->Nodes;
// Check for a node in the collection.
if (myNodeCollection->Contains(myTreeNode2)) {
myLabel->Text = String::Concat(myLabel->Text,
S"Node2 is at index: ",
__box(myNodeCollection->IndexOf(myTreeNode2)));
}
myLabel->Text = String::Concat(myLabel->Text,
S"\n\nElements of the TreeNodeCollection:\n");
// Create an enumerator for the collection.
IEnumerator* myEnumerator = myNodeCollection->GetEnumerator();
while(myEnumerator->MoveNext()) {
myLabel->Text = String::Concat(myLabel->Text,
(dynamic_cast<TreeNode*>(
myEnumerator->Current))->Text, S"\n");
}
}
[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
参照
TreeNodeCollection クラス | TreeNodeCollection メンバ | System.Windows.Forms 名前空間