之前我问过一个关于我的dataGridView性能的问题,因为它显示了大量基于传入流添加的行.给出了多种解决方案,其中一种解决方案支持虚拟模式 MSDN有一篇关于这个主题的文章,但它感觉比我需要的更复杂,因为它使用数据库和可编辑字段.我的DataGridView仅用于显示,我显示的数据放在List中.
在我接受答案后,我收到了这个链接:http://www.codeproject.com/Articles/23937/PagingANN-with havenGridView-in-VirtualMode.即使使用数据库示例,它也更适合我需要的东西.包含我要显示的数据的My List声明如下:
List<ResultRow> captureResults = new List<ResultRow>();
Run Code Online (Sandbox Code Playgroud)
ResultRow对象定义如下:
/* Simplified */
public class ResultRow
{
private int first = 0;
private string second = "";
private UInt64 third = 0;
private IPAddress fourth = null;
/* etc */
public ResultRow()
{
}
public void Set (<the values>) //In actuallity a KeyValuePair
{
//field gets set here
}
public UInt64 Third
{
get { return third; }
set { third = value; }
} …Run Code Online (Sandbox Code Playgroud) 我正在构建一个必须显示从外部系统接收的数据的应用程序.这些数据可以非常快速地进入,而每行占用的字节数相对较小.这意味着每个时间单元必须添加许多行.我目前正处于这样一个阶段,我看到我收到的数据比我能处理的速度快,这意味着我的内存使用率正在上升.
我认为这很大一部分与绘制实际的dataGridView有关.我对dataGridView做了一些调整,希望它能提高性能.(例如禁用自动尺寸,特殊样式等)
在最近的一次添加中,我添加了行的颜色,这是必需的.目前我的申请表如下:
实际添加发生在具有2个参数的函数中:1.包含列(项)项的列表2.行的颜色.(颜色)
它看起来如下(半伪):
/* Store the color for the row in the color list so it is accessible from the event */
rowColors.Add(rowColor); //Class variable that stored the colors of the rows used in the DataGridCellFormatting event
/* Create the row that is to be added. */
ResultRow resultRow = new ResultRow();
foreach(item in items)
{
resultRow.Set(item); /* It's actually a dictionary because some fields are optional, hence this instead of a direct constructor call) …Run Code Online (Sandbox Code Playgroud)