次の方法で共有


TreeNode.Index プロパティ

ツリー ノード コレクション内のツリー ノードの位置を取得します。

Public ReadOnly Property Index As Integer
[C#]
public int Index {get;}
[C++]
public: __property int get_Index();
[JScript]
public function get Index() : int;

プロパティ値

Nodes コレクション内のツリー ノードの位置を表す 0 から始まるインデックス値。

使用例

[Visual Basic, C#, C++] TreeView.SelectedNodeParent プロパティが表す TreeNodeText プロパティと Index プロパティの値を表示する例を次に示します。この例は、 TreeView コントロールが配置された Form があることを前提にしています。 TreeView コントロールは 2 つ以上のルート ノードを持ち、各ルート ノードに 1 つ以上の子ノードを持っている必要があります。

 
Private Sub treeView1_AfterSelect(sender As Object, _
  e As TreeViewEventArgs) Handles treeView1.AfterSelect
   ' Display the Text and Index of the 
   ' selected tree node's Parent. 
   If (Not e.Node.Parent Is Nothing) 
      If (e.Node.Parent.GetType() Is GetType(TreeNode)) Then
         statusBar1.Text = "Parent: " + e.Node.Parent.Text + _
           ControlChars.Cr + "Index Position: " + e.Node.Parent.Index.ToString()
      End If
   Else
      statusBar1.Text = "No parent node."
   End If
End Sub 

[C#] 
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{  
   /* Display the Text and Index of the 
    * selected tree node's Parent. */
   if(e.Node.Parent!= null && 
     e.Node.Parent.GetType() == typeof(TreeNode) )
   {
      statusBar1.Text = "Parent: " + e.Node.Parent.Text + "\n"
         + "Index Position: " + e.Node.Parent.Index.ToString();
   }
   else
   {
      statusBar1.Text = "No parent node.";
   }
}

[C++] 
private:
   void treeView1_AfterSelect(Object* /*sender*/, TreeViewEventArgs* e) {
      /* Display the Text and Index of the
      * selected tree node's Parent. */
      if (e->Node->Parent!= 0 &&
         e->Node->Parent->GetType() == __typeof(TreeNode)) {
            statusBar1->Text = String::Format( S"Parent: {0}\n Index Position: {1}", e->Node->Parent->Text, __box(e->Node->Parent->Index));
         } else {
            statusBar1->Text = S"No parent node.";
         }
   }

[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 名前空間