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

- 或 -

value 具有 trueSelected 属性值。

- 或 -

此操作将在未冻结的行之后插入一个冻结的行,或在冻结的行之前插入一个未冻结的行。

value 包含的单元格比控件中的列多。

注解

此成员是显式接口成员的实现。 它只能在 DataGridViewRowCollection 实例被强制转换为 IList 接口时使用。

此方法调用 Insert(Int32, DataGridViewRow) 重载,在将重载强制转换为 后传入 DataGridViewRow值。

添加新行时,控件中的行不会自动排序。 若要将新行排序到正确的位置,请在事件处理程序中DataGridView.RowsAdded调用 DataGridView.Sort 方法。 你可能还希望在事件处理程序中CellValueChanged调用 DataGridView.Sort 方法,以在用户修改单元格时对行进行排序。

适用于

另请参阅