共用方式為


DataGridViewRowCollection.Insert 方法

定義

將一列或多列插入集合。

多載

名稱 Description
Insert(Int32, DataGridViewRow)

將指定的 DataGridViewRow 資料插入集合中。

Insert(Int32, Int32)

在指定位置插入指定數量的列數。

Insert(Int32, Object[])

在集合中指定位置插入一列,並用指定的物件填充儲存格。

Insert(Int32, DataGridViewRow)

來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs

將指定的 DataGridViewRow 資料插入集合中。

public:
 virtual void Insert(int rowIndex, System::Windows::Forms::DataGridViewRow ^ dataGridViewRow);
public virtual void Insert(int rowIndex, System.Windows.Forms.DataGridViewRow dataGridViewRow);
abstract member Insert : int * System.Windows.Forms.DataGridViewRow -> unit
override this.Insert : int * System.Windows.Forms.DataGridViewRow -> unit
Public Overridable Sub Insert (rowIndex As Integer, dataGridViewRow As DataGridViewRow)

參數

rowIndex
Int32

插入該列的位置。

例外狀況

rowIndex 小於零或大於集合中的列數。

dataGridViewRownull

相關 DataGridView 控制項執行以下其中一項動作,暫時阻止新增列:

  • 選取控制組中的所有細胞。

  • 清除選擇。

-或-

此方法由處理器呼叫,用於以下 DataGridView 事件之一:

-或-

DataSourceDataGridView性質不是null

-或-

rowIndex 等於集合中的列數,且 AllowUserToAddRowsDataGridView 性質設為 true

-或-

DataGridView 沒有柱子。

-或-

DataGridViewdataGridViewRow性質不是null

-或-

dataGridViewRowSelected 性質值為 true

-或-

此操作會在未凍結的列後插入一列,或在凍結列前插入一列未凍結的列。

dataGridViewRow 其儲存格數比控制組的欄數還多。

備註

Insert(Int32, DataGridViewRow)此方法若可能,會在 中加入一列DataGridViewRowCollection共用。 否則,新一排將不共用。 欲了解更多資訊,請參閱 Windows 表單 DataGridView 控制項縮放的最佳實務

控制項中的列在新增列時不會自動排序。 要將新列排序到正確位置,請在事件處理程序DataGridView.RowsAdded中呼叫該DataGridView.Sort方法。 你也可以在事件處理器中呼叫 DataGridView.Sort 該方法 CellValueChanged ,當使用者修改儲存格時,來排序資料列。

另請參閱

適用於

Insert(Int32, Int32)

來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs

在指定位置插入指定數量的列數。

public:
 virtual void Insert(int rowIndex, int count);
public virtual void Insert(int rowIndex, int count);
abstract member Insert : int * int -> unit
override this.Insert : int * int -> unit
Public Overridable Sub Insert (rowIndex As Integer, count As Integer)

參數

rowIndex
Int32

插入排的位置。

count
Int32

要插入 DataGridViewRowCollection. 的列數。

例外狀況

rowIndex 小於零或大於集合中的列數。

-或-

count 小於1。

相關 DataGridView 控制項執行以下其中一項動作,暫時阻止新增列:

  • 選取控制組中的所有細胞。

  • 清除選擇。

-或-

此方法由處理器呼叫,用於以下 DataGridView 事件之一:

-或-

DataSourceDataGridView性質不是null

-或-

DataGridView 沒有柱子。

-或-

rowIndex 等於集合中的列數,且 AllowUserToAddRowsDataGridView 性質設為 true

-或-

屬性回傳 RowTemplate 的列中儲存格數比控制項中的欄位數還多。

-或-

此操作會在未凍結的列後插入一列,或在凍結列前插入一列未凍結的列。

備註

Insert(Int32, Int32) 方法會新增基於 RowTemplateDataGridView列。 新排會共用,如果可能的話。 確保屬性中 RowTemplate 指定的列能共享,以達到最佳的擴展性。 欲了解更多資訊,請參閱 Windows 表單 DataGridView 控制項縮放的最佳實務

控制項中的列在新增列時不會自動排序。 要將新列排序到正確位置,請在事件處理程序DataGridView.RowsAdded中呼叫該DataGridView.Sort方法。 你也可以在事件處理器中呼叫 DataGridView.Sort 該方法 CellValueChanged ,當使用者修改儲存格時,來排序資料列。

另請參閱

適用於

Insert(Int32, Object[])

來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs
來源:
DataGridViewRowCollection.cs

在集合中指定位置插入一列,並用指定的物件填充儲存格。

public:
 virtual void Insert(int rowIndex, ... cli::array <System::Object ^> ^ values);
public virtual void Insert(int rowIndex, params object[] values);
abstract member Insert : int * obj[] -> unit
override this.Insert : int * obj[] -> unit
Public Overridable Sub Insert (rowIndex As Integer, ParamArray values As Object())

參數

rowIndex
Int32

插入該列的位置。

values
Object[]

新一列的儲存格中可變數量的物件。

例外狀況

rowIndex 小於零或大於集合中的列數。

valuesnull

相關 DataGridView 控制項執行以下其中一項動作,暫時阻止新增列:

  • 選取控制組中的所有細胞。

  • 清除選擇。

-或-

此方法由處理器呼叫,用於以下 DataGridView 事件之一:

-或-

VirtualMode 的屬性 DataGridView 被設定為 true

-或-

DataSourceDataGridView性質不是null

-或-

DataGridView 沒有柱子。

-或-

rowIndex 等於集合中的列數,且 AllowUserToAddRowsDataGridView 性質設為 true

-或-

DataGridView控制RowTemplate屬性回傳的列屬性不是 null

-或-

此操作會在未凍結的列後插入一列,或在凍結列前插入一列未凍結的列。

控制項 RowTemplate 屬性回傳的列中,儲存格數比控制項中的欄位數還多。

備註

Insert(Int32, Object[])方法會在 中加入一列未共享的。DataGridViewRowCollection

控制項中的列在新增列時不會自動排序。 要將新列排序到正確位置,請在事件處理程序DataGridView.RowsAdded中呼叫該DataGridView.Sort方法。 你也可以在事件處理器中呼叫 DataGridView.Sort 該方法 CellValueChanged ,當使用者修改儲存格時,來排序資料列。

另請參閱

適用於