TreeNodeCollection.Insert 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将集合中的一项插入指定位置。
重载
| Insert(Int32, String, String, String, String) | 创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。 | 
| Insert(Int32, String, String, Int32, Int32) | 创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。 | 
| Insert(Int32, String, String, String) | 创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。 | 
| Insert(Int32, String, String) | 创建具有指定文本和键的树节点,并将其插入集合中。 | 
| Insert(Int32, TreeNode) | 在树节点集合中的指定位置插入现有树节点。 | 
| Insert(Int32, String) | 创建具有指定文本的树节点,并将其插入指定索引处。 | 
| Insert(Int32, String, String, Int32) | 创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。 | 
Insert(Int32, String, String, String, String)
创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。
public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ key, System::String ^ text, System::String ^ imageKey, System::String ^ selectedImageKey);public virtual System.Windows.Forms.TreeNode Insert (int index, string key, string text, string imageKey, string selectedImageKey);abstract member Insert : int * string * string * string * string -> System.Windows.Forms.TreeNode
override this.Insert : int * string * string * string * string -> System.Windows.Forms.TreeNodePublic Overridable Function Insert (index As Integer, key As String, text As String, imageKey As String, selectedImageKey As String) As TreeNode参数
- index
- Int32
集合中要插入节点的位置。
- key
- String
树节点的名称。
- text
- String
要在树节点中显示的文本。
- imageKey
- String
要在树节点中显示的图像的键。
- selectedImageKey
- String
处于选定状态时要在树节点中显示的图像的键。
返回
已插入到集合中的 TreeNode。
注解
如果该属性设置为 trueSorted,则index忽略参数值。 插入 TreeNode 树视图,并 TreeView 再次排序。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
该Name属性对应于中 TreeNodeCollectiona TreeNode 的键。
参数imageKey引用父级TreeView属性中的ImageList图像。
参数selectedimageKey引用父级TreeView属性中的StateImageList图像。
适用于
Insert(Int32, String, String, Int32, Int32)
创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。
public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ key, System::String ^ text, int imageIndex, int selectedImageIndex);public virtual System.Windows.Forms.TreeNode Insert (int index, string key, string text, int imageIndex, int selectedImageIndex);abstract member Insert : int * string * string * int * int -> System.Windows.Forms.TreeNode
override this.Insert : int * string * string * int * int -> System.Windows.Forms.TreeNodePublic Overridable Function Insert (index As Integer, key As String, text As String, imageIndex As Integer, selectedImageIndex As Integer) As TreeNode参数
- index
- Int32
集合中要插入节点的位置。
- key
- String
树节点的名称。
- text
- String
要在树节点中显示的文本。
- imageIndex
- Int32
要在树节点中显示的图像的索引。
- selectedImageIndex
- Int32
处于选定状态时要在树节点中显示的图像的索引。
返回
已插入到集合中的 TreeNode。
注解
如果该属性设置为 trueSorted,则index忽略参数值。 插入 TreeNode 树视图,并 TreeView 再次排序。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
该Name属性对应于中 TreeNodeCollectiona TreeNode 的键。
参数imageIndex引用父级TreeView属性中的ImageList图像。
参数selectedimageIndex引用父级TreeView属性中的StateImageList图像。
适用于
Insert(Int32, String, String, String)
创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。
public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ key, System::String ^ text, System::String ^ imageKey);public virtual System.Windows.Forms.TreeNode Insert (int index, string key, string text, string imageKey);abstract member Insert : int * string * string * string -> System.Windows.Forms.TreeNode
override this.Insert : int * string * string * string -> System.Windows.Forms.TreeNodePublic Overridable Function Insert (index As Integer, key As String, text As String, imageKey As String) As TreeNode参数
- index
- Int32
集合中要插入节点的位置。
- key
- String
树节点的名称。
- text
- String
要在树节点中显示的文本。
- imageKey
- String
要在树节点中显示的图像的键。
返回
已插入到集合中的 TreeNode。
注解
如果该属性设置为 trueSorted,则index忽略参数值。 插入 TreeNode 树视图,并 TreeView 再次排序。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
该Name属性对应于中 TreeNodeCollectiona TreeNode 的键。
参数imageKey引用父级TreeView属性中的ImageList图像。
适用于
Insert(Int32, String, String)
创建具有指定文本和键的树节点,并将其插入集合中。
public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ key, System::String ^ text);public virtual System.Windows.Forms.TreeNode Insert (int index, string key, string text);abstract member Insert : int * string * string -> System.Windows.Forms.TreeNode
override this.Insert : int * string * string -> System.Windows.Forms.TreeNodePublic Overridable Function Insert (index As Integer, key As String, text As String) As TreeNode参数
- index
- Int32
集合中要插入节点的位置。
- key
- String
树节点的名称。
- text
- String
要在树节点中显示的文本。
返回
已插入到集合中的 TreeNode。
注解
如果该属性设置为 trueSorted,则index忽略参数值。 插入 TreeNode 树视图,并 TreeView 再次排序。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
该Name属性对应于中 TreeNodeCollectiona TreeNode 的键。
适用于
Insert(Int32, TreeNode)
在树节点集合中的指定位置插入现有树节点。
public:
 virtual void Insert(int index, System::Windows::Forms::TreeNode ^ node);public virtual void Insert (int index, System.Windows.Forms.TreeNode node);abstract member Insert : int * System.Windows.Forms.TreeNode -> unit
override this.Insert : int * System.Windows.Forms.TreeNode -> unitPublic Overridable Sub Insert (index As Integer, node As TreeNode)参数
- index
- Int32
集合中要插入树节点的索引位置。
例外
node 目前分配给了另一个 TreeView。
示例
下面的代码示例从一个树节点中删除所选树节点,如果两个 TreeView 树节点集合不是只读的,则将其添加到另一个节点。 单击 a Button 时,TreeNode将使用Remove该方法从一个属性中删除该属性的表示TreeView.SelectedNode,并使用该方法添加到另一TreeView个TreeViewInsert属性。 此示例要求你有一个包含两TreeView个Form控件和一个Button控件。 TreeView控件应命名treeView1和 treeView2。
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
注解
如果该属性设置为 trueTreeView.Sorted,则index忽略参数值。 插入 TreeNode 树视图和 TreeView 度假村。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
若要删除之前添加的、TreeNode使用Remove或RemoveAtClear方法。
适用于
Insert(Int32, String)
创建具有指定文本的树节点,并将其插入指定索引处。
public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ text);public virtual System.Windows.Forms.TreeNode Insert (int index, string text);abstract member Insert : int * string -> System.Windows.Forms.TreeNode
override this.Insert : int * string -> System.Windows.Forms.TreeNodePublic Overridable Function Insert (index As Integer, text As String) As TreeNode参数
- index
- Int32
集合中要插入节点的位置。
- text
- String
要在树节点中显示的文本。
返回
已插入到集合中的 TreeNode。
注解
如果该属性设置为 trueSorted,则index忽略参数值。 插入 TreeNode 树视图,并 TreeView 再次排序。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
适用于
Insert(Int32, String, String, Int32)
创建具有指定键、文本和图像的树节点,并将其插入集合中的指定索引处。
public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ key, System::String ^ text, int imageIndex);public virtual System.Windows.Forms.TreeNode Insert (int index, string key, string text, int imageIndex);abstract member Insert : int * string * string * int -> System.Windows.Forms.TreeNode
override this.Insert : int * string * string * int -> System.Windows.Forms.TreeNodePublic Overridable Function Insert (index As Integer, key As String, text As String, imageIndex As Integer) As TreeNode参数
- index
- Int32
集合中要插入节点的位置。
- key
- String
树节点的名称。
- text
- String
要在树节点中显示的文本。
- imageIndex
- Int32
要在树节点中显示的图像的索引。
返回
已插入到集合中的 TreeNode。
注解
如果该属性设置为 trueSorted,则index忽略参数值。 插入 TreeNode 树视图,并 TreeView 再次排序。
还可以使用Add或AddRange方法向TreeNode集合添加新对象。
该Name属性对应于中 TreeNodeCollectiona TreeNode 的键。
参数imageIndex引用父级TreeView属性中的ImageList图像。