TreeNodeCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定集合中的樹節點。
多載
| 名稱 | Description |
|---|---|
| Item[Int32] |
在集合中指定的索引位置取得或設定 。TreeNode |
| Item[String] |
從集合中取得帶有指定鍵的樹節點。 |
Item[Int32]
在集合中指定的索引位置取得或設定 。TreeNode
public:
virtual property System::Windows::Forms::TreeNode ^ default[int] { System::Windows::Forms::TreeNode ^ get(int index); void set(int index, System::Windows::Forms::TreeNode ^ value); };
public virtual System.Windows.Forms.TreeNode this[int index] { get; set; }
member this.Item(int) : System.Windows.Forms.TreeNode with get, set
Default Public Overridable Property Item(index As Integer) As TreeNode
參數
屬性值
該 TreeNode 位置位於集合中指定的索引位置。
例外狀況
.NET 6 及以上版本: index 是 null。
該 index 值小於 0,或大於集合中最後一個索引。
範例
以下程式碼範例若其TreeNode.Text屬性設為「Node0」,則會移除第一個。TreeNodeTreeView 當點擊 a Button 時,TreeNodeTreeView第一個 a 會被刪除。RemoveAt 此範例要求你在 a Form上創建了 a TreeView 和 aButton。 你TreeNodeTreeView第一個應該有「Node0」的文字屬性。
void button2_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Delete the first TreeNode in the collection
// if the Text property is S"Node0."
if ( this->treeView1->Nodes[ 0 ]->Text->Equals( "Node0" ) )
{
this->treeView1->Nodes->RemoveAt( 0 );
}
}
private void button2_Click(object sender, EventArgs e)
{
// Delete the first TreeNode in the collection
// if the Text property is "Node0."
if(this.treeView1.Nodes[0].Text == "Node0")
{
this.treeView1.Nodes.RemoveAt(0);
}
}
Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
' Delete the first TreeNode in the collection
' if the Text property is "Node0."
If Me.treeView1.Nodes(0).Text = "Node0" Then
Me.treeView1.Nodes.RemoveAt(0)
End If
End Sub
備註
若要將物件指派 TreeNode 到特定位置,或從 TreeNodeCollection中擷取物件,您可以使用特定的索引值來參考集合物件。 的 TreeNodeCollection 索引值為零為基礎的索引。
另請參閱
適用於
Item[String]
從集合中取得帶有指定鍵的樹節點。
public:
virtual property System::Windows::Forms::TreeNode ^ default[System::String ^] { System::Windows::Forms::TreeNode ^ get(System::String ^ key); };
public virtual System.Windows.Forms.TreeNode this[string key] { get; }
public virtual System.Windows.Forms.TreeNode? this[string? key] { get; }
member this.Item(string) : System.Windows.Forms.TreeNode
Default Public Overridable ReadOnly Property Item(key As String) As TreeNode
參數
屬性值
備註
該Name性質對應於 中 a 的TreeNodeTreeNodeCollection鍵。
關鍵比較並不區分大小寫。 若 key 參數為 null 或 為空字串,則 Item[] 該屬性回傳 null。