DataGridViewColumnCollection.AddRange(DataGridViewColumn[]) 方法

定义

将某一范围的列添加到集合中。

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())

参数

dataGridViewColumns
DataGridViewColumn[]

要添加的 DataGridViewColumn 对象的数组。

例外

dataGridViewColumnsnull

关联的 DataGridView 控件正在执行以下操作之一,该操作暂时禁止添加新列:

示例

下面的代码示例演示了此方法的使用。 此示例是 How to: Set the Sizing Modes of the Windows 窗体 DataGridView 控件中提供的大型示例的一部分。

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."})

适用于

另请参阅