DataGridViewCellCollection.Add Method (DataGridViewCell)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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


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.

Exception Condition

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


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
Available since 2.0
Return to top