DataGridViewRowCollection.IList.Insert(Int32, Object) 方法

定義

DataGridViewRow 插入集合中指定的索引處。

 virtual void System.Collections.IList.Insert(int index, System::Object ^ value) = System::Collections::IList::Insert;
void IList.Insert (int index, object value);
void IList.Insert (int index, object? value);
abstract member System.Collections.IList.Insert : int * obj -> unit
override this.System.Collections.IList.Insert : int * obj -> unit
Sub Insert (index As Integer, value As Object) Implements IList.Insert

參數

index
Int32

應在 value 插入以零為起始的索引。

實作

例外狀況

index 小於零或大於集合中的資料列數目。

valuenull

關聯的 DataGridView 控制項正在執行下列其中一個動作,會暫時防止加入新的資料列:

  • 選取控制項中的所有儲存格。

  • 清除選取範圍。

-或-

針對下列其中一個 DataGridView 事件 ,從處理常式呼叫這個方法:

-或-

DataGridViewDataSource 屬性不是 null

-或-

index 等於集合中的資料列數目,且 DataGridViewAllowUserToAddRows 屬性設定為 true

-或-

DataGridView 沒有資料行。

-或-

valueDataGridView 屬性不是 null

-或-

valueSelected 屬性值為 true

-或-

這項作業會在未凍結的資料列之後插入凍結的資料列,或是在凍結的資料列之前插入未凍結的資料列。

value 所包含的儲存格多於控制項中的資料行數目。

備註

這個成員是明確介面成員實作, 只有在 DataGridViewRowCollection 執行個體轉換成 IList 介面時,才能使用這個成員。

這個方法會 Insert(Int32, DataGridViewRow) 呼叫多載,並將它 DataGridViewRow 轉換成 之後傳入值。

加入新資料列時,控制項中的資料列不會自動排序。 若要將新資料列排序成正確的位置,請在事件處理常式中 DataGridView.RowsAdded 呼叫 DataGridView.Sort 方法。 您也可以在事件處理常式中 CellValueChanged 呼叫 DataGridView.Sort 方法,以在使用者修改儲存格時排序資料列。

適用於

另請參閱