views:

31

answers:

0

Hi All,

I need to use a the DataGridView control to display a large number of columns. I haveed a DataGridViewCell class that specifies a custom Paint method for each cell. I have add the columns like so.....

        int ColumnCount = 5000;
        DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
        for (int i = 0; i < ColumnCount; i++)
        {
            dataGridView1.Columns.Add(new DataGridViewColumn() { CellTemplate = cell, FillWeight = 1 });
        }

The problem is, this takes ages to add all the columns, much longer than it should really take. When I add the columns I can see the size of the scroll bar at the bottom of the DataGridView getting smaller like the grid is drawing each column each time I add one.

Does anyone know of a quicker way to add a large number of columns, or how to prevent the DataGridView updating until all the columns have been added?

I've tried disabling resizing, SuspendLayout(), and setting dataGridView1.Visible = false......