开发者

DataGridView and adding columns programmatically

I need to use a the DataGridView control to display a large number of columns. I have a DataGridViewCell class that specifies开发者_StackOverflow社区 a custom Paint method for each cell. I have added 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.


If you use the VirtualMode = TRUE for the DataGridView, you can refresh ONLY the screen portion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜