DataGridViewColumnCollection.IList.Add Method (Object)


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

This API supports the product infrastructure and is not intended to be used directly from your code.

Adds an object to the end of the collection.

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

int IList.Add(
	object value


Type: System.Object

The Object to add to the end of the collection. The value can be null.

Return Value

Type: System.Int32

The index at which value has been added.

Exception Condition

value is not a DataGridViewColumn.


value is null.


The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added:

  • Selecting all cells in the control.

  • Clearing the selection.

  • Updating column DisplayIndex property values.


This method is being called from a handler for one of the following DataGridView events:


The column indicated by value already belongs to a DataGridView control.


The SortMode property value of the column indicated by value is Automatic and the DataGridView.SelectionMode property value is FullColumnSelect or ColumnHeaderSelect. Use the control ISupportInitialize.BeginInit and ISupportInitialize.EndInit methods to temporarily set conflicting property values.


The InheritedAutoSizeMode property value of the column indicated by value is ColumnHeader and the DataGridView.ColumnHeadersVisible property value is false.


The column indicated by value has an InheritedAutoSizeMode property value of Fill and a Frozen property value of true.


The column indicated by value has a FillWeight property value that would cause the combined FillWeight values of all columns in the control to exceed 65535.


The column indicated by value has DisplayIndex and Frozen property values that would display it among a set of adjacent columns with the opposite Frozen property value.


The DataGridView control contains at least one row and the column indicated by value has a CellType property value of null.

This member is an explicit interface member implementation. It can be used only when the DataGridViewColumnCollection instance is cast to an IList interface.

.NET Framework
Available since 2.0
Return to top