如何优化的DataGridView的性能 [英] How to optimize the performance of DataGridView

查看:353
本文介绍了如何优化的DataGridView的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的Windows应用程序的形式DataGridView控件。此的DataGridView填充一个纯文本文件(由用户在运行时指定)的基础上。因此列和行的数量是动态计算的。现在的每一件事工作正常,预期唯一的问题是,我的DataGridView花了很多时间来加载数据,有没有什么办法来优化DataGridView中的表现?

提示:正常情况下,datagridview的1024,则为列和Almos酒店100行

以下是code来填充我的DataGridView

  dataGridView1.ColumnCount = nColumnCount;

的for(int i = 0; I< CurrPageLines.Length;我++)
{
    字符串sCurrLinecontents = CurrPageLines [I]
    INT N = dataGridView1.Rows.Add();
    对于(INT J = 0; J< /*nColumnCount*/sCurrLinecontents.Length; J ++)
    {
        dataGridView1.Rows [N] .Cells [J]。价值= sCurrLinecontents [J]。
    }
}
 

解决方案

有上的如何使用的datagridview 的虚拟模式。它甚至还带有一个很好的演练例子。虽然它似乎是更有针对性的对大量的行,而不是大量列的可能仍然是有用的。

更新:如果你是刚刚经历了加载数据时的延迟,你也许可以通过创建一个数据表或<$ C,以改善的事情$ C>的BindingList 从文本文件,然后将绑定到视图。

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

这篇关于如何优化的DataGridView的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆