TreeNode.Index 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得樹狀節點集合中的樹狀節點位置。
public:
property int Index { int get(); };
public int Index { get; }
member this.Index : int
Public ReadOnly Property Index As Integer
屬性值
以零起始的索引值,表示 Nodes 集合中的樹狀節點位置。
範例
下列程式碼範例會顯示 Text 所表示 ParentTreeView.SelectedNode 之 的 TreeNode 和 Index 屬性值。 此範例會要求您具有 FormTreeView 控制項的 。 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