Επεξεργασία

Κοινή χρήση μέσω


DataGridViewColumnCollection.AddRange(DataGridViewColumn[]) Method

Definition

Adds a range of columns to the collection.

public:
 virtual void AddRange(... cli::array <System::Windows::Forms::DataGridViewColumn ^> ^ dataGridViewColumns);
public virtual void AddRange (params System.Windows.Forms.DataGridViewColumn[] dataGridViewColumns);
abstract member AddRange : System.Windows.Forms.DataGridViewColumn[] -> unit
override this.AddRange : System.Windows.Forms.DataGridViewColumn[] -> unit
Public Overridable Sub AddRange (ParamArray dataGridViewColumns As DataGridViewColumn())

Parameters

dataGridViewColumns
DataGridViewColumn[]

An array of DataGridViewColumn objects to add.

Exceptions

dataGridViewColumns 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.

-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 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 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.

Examples

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.

dataGridView1.Columns.AddRange(new DataGridViewTextBoxColumn[] { 
    idColumn, titleColumn, subTitleColumn, 
    summaryColumn, contentColumn });
dataGridView1.Rows.Add(new String[] { "1", 
    "A Short Title", "A Longer SubTitle", 
    "A short description of the main point.", 
    "The full contents of the topic, with detailed examples." });
dataGridView1.Columns.AddRange(New DataGridViewTextBoxColumn() { _
    idColumn, titleColumn, subTitleColumn, _
    summaryColumn, contentColumn})
dataGridView1.Rows.Add(New String() {"1", _
    "A Short Title", "A Longer SubTitle", _
    "A short description of the main point.", _
    "The full contents of the topic, with detailed examples."})

Applies to

See also