TreeNode.Index 속성

정의

트리 노드 컬렉션에 있는 트리 노드의 위치를 가져옵니다.

public:
 property int Index { int get(); };
public int Index { get; }
member this.Index : int
Public ReadOnly Property Index As Integer

속성 값

Int32

Nodes 컬렉션에 있는 트리 노드의 위치를 나타내는 인덱스(0부터 시작하는) 값입니다.

예제

다음 코드 예제에서는 속성이 Text 나타내는 Parent 값과 Index 속성 TreeView.SelectedNode값을 TreeNode 표시합니다. 이 예제에서는 컨트롤이 Form TreeView 있어야 합니다. TreeView 각각 하나 이상의 자식 노드가 있는 두 개 이상의 루트 노드가 있어야 합니다.

private:
   void treeView1_AfterSelect( Object^ /*sender*/, TreeViewEventArgs^ e )
   {
      /* Display the Text and Index of the
            * selected tree node's Parent. */
      if ( e->Node->Parent != nullptr && e->Node->Parent->GetType() == TreeNode::typeid )
      {
         statusBar1->Text = String::Format( "Parent: {0}\n Index Position: {1}", e->Node->Parent->Text, e->Node->Parent->Index );
      }
      else
      {
         statusBar1->Text = "No parent node.";
      }
   }
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.";
   }
}
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 (e.Node.Parent IsNot 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

적용 대상