开发者

How to optimize the performance of DataGridView

I have a DataGridView control on my windows application form. This DataGridView is populated on the basis of a plain text file (specified by user at run t开发者_开发知识库ime). Hence the number of columns and rows are calculated dynamically. Now the every thing works fine as expected the only issue is that my DataGridView took a lot of time to load data, is there any way to optimize the performance of DataGridView?

Hint: Normally the datagridview contians 1024 columns and almos 100 rows.

Following is the code for populating my DataGridView

dataGridView1.ColumnCount = nColumnCount;

for (int i = 0; i < CurrPageLines.Length; i++)
{
    string sCurrLinecontents = CurrPageLines[i];
    int n = dataGridView1.Rows.Add();
    for (int j = 0; j < /*nColumnCount*/sCurrLinecontents.Length; j++)
    {
        dataGridView1.Rows[n].Cells[j].Value = sCurrLinecontents[j];
    }
}


There is an article on MSDN on how use the virtual mode of the datagridview. It even comes with a nice walkthrough example. Although it seems to be more targeted towards lots of rows instead of lots of columns it might still be useful.

Update: If you are just experiencing delays when loading data you might be able to improve things by creating a DataTable or a BindingList from your textfile and then bind that to the view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜