Export (0) Print
Expand All

DataGridViewCellCollection.Add Method

Adds a cell to the collection.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual int Add(
	DataGridViewCell dataGridViewCell
)

Parameters

dataGridViewCell
Type: System.Windows.Forms.DataGridViewCell

A DataGridViewCell to add to the collection.

Return Value

Type: System.Int32
The position in which to insert the new element.

ExceptionCondition
InvalidOperationException

The row that owns this DataGridViewCellCollection already belongs to a DataGridView control.

-or-

dataGridViewCell already belongs to a DataGridViewRow.

Use this method to populate a DataGridViewRow with cells before you add the row to a DataGridView control. Once you add the row to a control, the number of cells it contains always matches the number of columns in the control, so this method is no longer useful.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft