DataGridViewColumn.AddRange problem

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



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 );
 
T

Tim Van Wassenhove

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top