次の方法で共有


TreeNodeCollection.Insert メソッド

定義

コレクション内の指定した場所に項目を挿入します。

オーバーロード

名前 説明
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)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

指定したキー、テキスト、およびイメージを持つツリー ノードを作成し、指定したインデックス位置にあるコレクションに挿入します。

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);
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.TreeNode
Public 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

注釈

Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewが再び並べ替えられます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

Name プロパティは、TreeNodeCollection内のTreeNodeのキーに対応します。

imageKey パラメーターは、親TreeViewImageList プロパティ内のイメージを参照します。

selectedimageKey パラメーターは、親TreeViewStateImageList プロパティ内のイメージを参照します。

適用対象

Insert(Int32, String, String, Int32, Int32)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

指定したキー、テキスト、およびイメージを持つツリー ノードを作成し、指定したインデックス位置にあるコレクションに挿入します。

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);
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.TreeNode
Public 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

注釈

Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewが再び並べ替えられます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

Name プロパティは、TreeNodeCollection内のTreeNodeのキーに対応します。

imageIndex パラメーターは、親TreeViewImageList プロパティ内のイメージを参照します。

selectedimageIndex パラメーターは、親TreeViewStateImageList プロパティ内のイメージを参照します。

適用対象

Insert(Int32, String, String, String)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

指定したキー、テキスト、およびイメージを持つツリー ノードを作成し、指定したインデックス位置にあるコレクションに挿入します。

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);
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.TreeNode
Public 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

注釈

Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewが再び並べ替えられます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

Name プロパティは、TreeNodeCollection内のTreeNodeのキーに対応します。

imageKey パラメーターは、親TreeViewImageList プロパティ内のイメージを参照します。

適用対象

Insert(Int32, String, String)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

指定したテキストとキーを持つツリー ノードを作成し、コレクションに挿入します。

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);
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.TreeNode
Public Overridable Function Insert (index As Integer, key As String, text As String) As TreeNode

パラメーター

index
Int32

ノードを挿入するコレクション内の場所。

key
String

ツリー ノードの名前。

text
String

ツリー ノードに表示するテキスト。

戻り値

コレクションに挿入された TreeNode

注釈

Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewが再び並べ替えられます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

Name プロパティは、TreeNodeCollection内のTreeNodeのキーに対応します。

適用対象

Insert(Int32, TreeNode)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

既存のツリー ノードを、指定した場所にあるツリー ノード コレクションに挿入します。

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 -> unit
Public Overridable Sub Insert (index As Integer, node As TreeNode)

パラメーター

index
Int32

ツリー ノードを挿入するコレクション内のインデックス付き場所。

node
TreeNode

コレクションに挿入する TreeNode

例外

現在、 node は別の TreeViewに割り当てられます。

次のコード例では、選択したツリー ノードを 1 つの TreeView から削除し、両方のツリー ノード コレクションが読み取り専用でない場合は別のツリー ノードに追加します。 Buttonをクリックすると、Remove メソッドを使用して、TreeView.SelectedNode プロパティによって表されるTreeNodeが 1 つのTreeViewから削除され、Insert メソッドを使用して他のTreeViewに追加されます。 この例では、2 つのTreeView コントロールとButtonを含むFormが必要です。 TreeView コントロールには、treeView1treeView2という名前を付ける必要があります。

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

注釈

TreeView.Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewがリリゾートされます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

前に追加した TreeNode を削除するには、 RemoveRemoveAt、または Clear メソッドを使用します。

TreeNodeは、一度に 1 つのTreeView コントロールにのみ割り当てることができます。 ツリー ノードを新しいツリー ビュー コントロールに追加するには、最初に他のツリー ビューから削除するか、複製する必要があります。

適用対象

Insert(Int32, String)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

指定したテキストを持つツリー ノードを作成し、指定したインデックス位置に挿入します。

public:
 virtual System::Windows::Forms::TreeNode ^ Insert(int index, System::String ^ text);
public virtual System.Windows.Forms.TreeNode Insert(int index, 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.TreeNode
Public Overridable Function Insert (index As Integer, text As String) As TreeNode

パラメーター

index
Int32

ノードを挿入するコレクション内の場所。

text
String

ツリー ノードに表示するテキスト。

戻り値

コレクションに挿入された TreeNode

注釈

Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewが再び並べ替えられます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

適用対象

Insert(Int32, String, String, Int32)

ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs
ソース:
TreeNodeCollection.cs

指定したキー、テキスト、およびイメージを持つツリー ノードを作成し、指定したインデックス位置にあるコレクションに挿入します。

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);
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.TreeNode
Public 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

注釈

Sorted プロパティが true に設定されている場合、index パラメーター値は無視されます。 TreeNodeがツリー ビューに挿入され、TreeViewが再び並べ替えられます。

AddメソッドまたはAddRange メソッドを使用して、新しいTreeNode オブジェクトをコレクションに追加することもできます。

Name プロパティは、TreeNodeCollection内のTreeNodeのキーに対応します。

imageIndex パラメーターは、親TreeViewImageList プロパティ内のイメージを参照します。

適用対象