DataGridViewRowCollection.IList.Add(Object) 方法

定義

DataGridViewRow 加入集合。

 virtual int System.Collections.IList.Add(System::Object ^ value) = System::Collections::IList::Add;
int IList.Add (object value);
int IList.Add (object? value);
abstract member System.Collections.IList.Add : obj -> int
override this.System.Collections.IList.Add : obj -> int
Function Add (value As Object) As Integer Implements IList.Add

參數

value
Object

要加入至 ObjectIList

傳回

DataGridViewRow 的索引。

實作

例外狀況

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

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

  • 清除選取範圍。

-或-

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

-或-

DataGridViewDataSource 屬性不是 null

-或-

DataGridView 沒有資料行。

-或-

valueDataGridView 屬性不是 null

-或-

valueSelected 屬性值為 true

-或-

這項作業會將凍結的資料列加在未凍結的資料列後面。

valuenull

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

備註

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

這個方法會 Add(DataGridViewRow) 呼叫 多載,並將 valueDataGridViewRow 轉換成 之後傳入 。

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

適用於

另請參閱