DataGridViewColumnCollection::AddRange Method (array<DataGridViewColumn^>^)
Adds a range of columns to the collection.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- dataGridViewColumns
-
Type:
array<System.Windows.Forms::DataGridViewColumn^>^
An array of DataGridViewColumn objects to add.
| Exception | Condition |
|---|---|
| ArgumentNullException | dataGridViewColumns is null. |
| InvalidOperationException | The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added:
-or- This method is being called from a handler for one of the following DataGridView events: -or- At least one of the values in dataGridViewColumns is null. -or- At least one of the columns in dataGridViewColumns already belongs to a DataGridView control. -or- At least one of the columns in dataGridViewColumns has a CellType property value of null and the DataGridView control contains at least one row. -or- At least one of the columns in dataGridViewColumns has a SortMode property value of 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. -or- At least one of the columns in dataGridViewColumns has an InheritedAutoSizeMode property value of ColumnHeader and the DataGridView::ColumnHeadersVisible property value is false. -or- At least one of the columns in dataGridViewColumns has an InheritedAutoSizeMode property value of Fill and a Frozen property value of true. -or- The columns in dataGridViewColumns have FillWeight property values that would cause the combined FillWeight values of all columns in the control to exceed 65535. -or- At least two of the values in dataGridViewColumns are references to the same DataGridViewColumn. -or- At least one of the columns in dataGridViewColumns has DisplayIndex and Frozen property values that would display it among a set of adjacent columns with the opposite Frozen property value. |
The following code example illustrates the use of this method. This example is part of a larger example available in How to: Set the Sizing Modes of the Windows Forms DataGridView Control.
Available since 2.0