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

- 或 -

value 具有 trueSelected 属性值。

- 或 -

此操作将在未冻结行之后添加一个冻结行。

valuenull

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

注解

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

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

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

适用于

另请参阅