TreeNode.Nodes 屬性

定義

取得指派給目前樹狀節點之 TreeNode 物件的集合。Gets the collection of TreeNode objects assigned to the current tree node.

public:
 property System::Windows::Forms::TreeNodeCollection ^ Nodes { System::Windows::Forms::TreeNodeCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.ListBindable(false)]
public System.Windows.Forms.TreeNodeCollection Nodes { get; }
member this.Nodes : System.Windows.Forms.TreeNodeCollection
Public ReadOnly Property Nodes As TreeNodeCollection

屬性值

TreeNodeCollection,表示指派給目前樹狀節點的樹狀節點。A TreeNodeCollection that represents the tree nodes assigned to the current tree node.

屬性

範例

下列程式碼範例會移除選取的樹狀節點TreeView ,並在兩個樹狀節點集合都不是唯讀時將它加入另一個。The following code example removes the selected tree node from one TreeView and adds it to another if both tree node collections are not read-only. TreeView Remove Insert當按TreeView.SelectedNode下時,會使用方法從一個中刪除,並使用方法將新增TreeView至另一個。 ButtonWhen a Button is clicked, the TreeView.SelectedNode is deleted from one TreeView using the Remove method and added to the other TreeView using the Insert method. 這個範例需要您有兩個TreeView名為treeView1treeView2Button控制項,以及上Form的。This example requires that you have two TreeView controls named treeView1 and treeView2, and a Button on a Form.

void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // If neither TreeNodeCollection is read-only, move the
   // selected node from treeView1 to treeView2.
   if (  !treeView1->Nodes->IsReadOnly &&  !treeView2->Nodes->IsReadOnly )
   {
      if ( treeView1->SelectedNode != nullptr )
      {
         TreeNode^ tn = treeView1->SelectedNode;
         treeView1->Nodes->Remove( tn );
         treeView2->Nodes->Insert( treeView2->Nodes->Count, tn );
      }
   }
}
private void button1_Click(object sender, EventArgs e)
{
   // If neither TreeNodeCollection is read-only, move the 
   // selected node from treeView1 to treeView2.
   if(!treeView1.Nodes.IsReadOnly && !treeView2.Nodes.IsReadOnly)
   {
      if(treeView1.SelectedNode != null)
      {
         TreeNode tn = treeView1.SelectedNode;
         treeView1.Nodes.Remove(tn);
         treeView2.Nodes.Insert(treeView2.Nodes.Count, tn);
      }
   }
}
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
   ' If neither TreeNodeCollection is read-only, move the 
   ' selected node from treeView1 to treeView2. 
   If Not treeView1.Nodes.IsReadOnly And Not treeView2.Nodes.IsReadOnly Then
      If (treeView1.SelectedNode IsNot Nothing) Then
         Dim tn As TreeNode = treeView1.SelectedNode
         treeView1.Nodes.Remove(tn)
         treeView2.Nodes.Insert(treeView2.Nodes.Count, tn)
      End If
   End If
End Sub

備註

屬性可以保留其他TreeNode物件的集合。 NodesThe Nodes property can hold a collection of other TreeNode objects. 集合中的每個樹狀節點都有一個Nodes可包含其本身TreeNodeCollection的屬性。Each of the tree node in the collection has a Nodes property that can contain its own TreeNodeCollection. 這個樹狀節點的嵌套可能會使流覽樹狀結構變得很難以。This nesting of tree nodes can make it difficult to navigate a tree structure. FullPath屬性可讓您更輕鬆地判斷樹狀結構中的位置。The FullPath property makes it easier to determine your location in a tree.

適用於

另請參閱