편집

다음을 통해 공유


TreeNodeCollection.Item[] Property

Definition

Gets or sets a tree node within the collection.

Overloads

Item[Int32]

Gets or sets the TreeNode at the specified indexed location in the collection.

Item[String]

Gets the tree node with the specified key from the collection.

Item[Int32]

Source:
TreeNodeCollection.cs
Source:
TreeNodeCollection.cs
Source:
TreeNodeCollection.cs

Gets or sets the TreeNode at the specified indexed location in the collection.

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

Parameters

index
Int32

The indexed location of the TreeNode in the collection.

Property Value

The TreeNode at the specified indexed location in the collection.

Exceptions

.NET 6 and later versions: index is null.

The index value is less than 0 or is greater than the last index in the collection.

The TreeNode that's being assigned to this index is already assigned to a different index or to a different TreeView control.

Examples

The following code example removes the first TreeNode from a TreeView if its TreeNode.Text property is set to "Node0". When a Button is clicked, the first TreeNode in the TreeView is deleted using the RemoveAt method. This example requires that you have created a TreeView and a Button on a Form. The first TreeNode in your TreeView should have a text property of "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

Remarks

To assign TreeNode objects to a specific location, or to retrieve them from the TreeNodeCollection, you can reference the collection object with a specific index value. The index value of the TreeNodeCollection is a zero-based index.

See also

Applies to

Item[String]

Source:
TreeNodeCollection.cs
Source:
TreeNodeCollection.cs
Source:
TreeNodeCollection.cs

Gets the tree node with the specified key from the collection.

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

Parameters

key
String

The name of the TreeNode to retrieve from the collection.

Property Value

The TreeNode with the specified key.

Remarks

The Name property corresponds to the key for a TreeNode in the TreeNodeCollection.

The key comparison is not case-sensitive. If the key parameter is null or an empty string, the Item[] property returns null.

Applies to