DataGridViewColumn.AddRange problem

  • Thread starter Thread starter Tim Van Wassenhove
  • Start date Start date
T

Tim Van Wassenhove

When i run the code below i recieve the following error message:
At least one of the DataGridView control's columns has no cell template.


---------------------------------------------------------------------------------
this.dataGridView1.Columns.Clear();

DataGridViewColumn[] columns = new DataGridViewColumn[750];
for ( int i = 0; i < columns.Length; ++i )
{
DataGridViewColumn column = new DataGridViewColumn();
column.CellTemplate = new DataGridViewTextBoxCell();
column.Width = 30;
column.FillWeight = 1;
columns = column;
// adding them one by one works
//this.dataGridView1.Columns.Add( column );
}

this.dataGridView1.Columns.AddRange( columns );
----------------------------------------------------------------------------------


Anyone that knows how i can speed up the addition of this many columns?
I've been experimenting with suspend/resume layout and toggling Visible property but none
of them seem to be make a significant difference.

Thanks in advance.
 
When i run the code below i recieve the following error message:
At least one of the DataGridView control's columns has no cell template.


---------------------------------------------------------------------------------
this.dataGridView1.Columns.Clear();

DataGridViewColumn[] columns = new DataGridViewColumn[750];
for ( int i = 0; i < columns.Length; ++i )
{
DataGridViewColumn column = new DataGridViewColumn();
column.CellTemplate = new DataGridViewTextBoxCell();
column.Width = 30;
column.FillWeight = 1;
columns = column;
// adding them one by one works
//this.dataGridView1.Columns.Add( column );
}

this.dataGridView1.Columns.AddRange( columns );
----------------------------------------------------------------------------------



The following code does work with AddRange (but still open for speed
improvements):


DataGridViewTextBoxColumn[] columns = new DataGridViewTextBoxColumn[750];
for ( int i = 0; i < 750; ++i )
{
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.HeaderText = String.Format( "{0:000}", i );
column.FillWeight = 1;
column.Width = 30;
columns = column;
}

this.dataGridView1.Columns.AddRange( columns );
 
The following code does work with AddRange (but still open for speed
improvements):


DataGridViewTextBoxColumn[] columns = new DataGridViewTextBoxColumn[750];
for ( int i = 0; i < 750; ++i )
{
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.HeaderText = String.Format( "{0:000}", i );
column.FillWeight = 1;
column.Width = 30;
columns = column;
}

this.dataGridView1.Columns.AddRange( columns );


Setting the ColumnHeadersHeightSizeMode property on DisableResizing
resulted in a serious improvement (from 15 seconds to 0.4 seconds) :))
 
Back
Top