How to add column to datagridview using AddRange c#

  • Thread starter Thread starter Mou_kolkata
  • Start date Start date
M

Mou_kolkata

Guest
i saw people use this below code to add many column at a time. here is code

var col3 = new DataGridViewTextBoxColumn();
var col4 = new DataGridViewCheckBoxColumn();

col3.HeaderText = "Column3";
col3.Name = "Column3";

col4.HeaderText = "Column4";
col4.Name = "Column4";

dataGridView1.Columns.AddRange(new DataGridViewColumn[] {col3,col4});

but my situation is bit different. this way i am adding column to datagridview in loop.

foreach (DataColumn column in retriever.Columns)
{
dataGridView1.Columns.Add(column.ColumnName, column.ColumnName);
}

anyone can tell me how to modify my above code to use addrange() instead of add() function. my intention is to add all columns at a time instead of adding loop.

Continue reading...
 
Back
Top