如何提高DataGridView的绘画表现? [英] How to improve painting performance of DataGridView?

查看:254
本文介绍了如何提高DataGridView的绘画表现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(抱歉坏英文)

我有一个问题的DataGridView 当它重新油漆的性能。

我使用了一个的DataGridView 来显示从外部应用程序流日志。从流消息进来以高频率(小于1毫秒)。如果我添加新行的DataGridView 立刻当每一个新的消息来了,的DataGridView 没有时间重新-paint本身的下一条消息到来之前。

一个可能的解决方案是使用一个队列来收集与队列中的消息的消息,并重新油漆的DataGridView 每100毫秒。这是好的,但的DataGridView 闪烁时,它自动滚动到最后一行。 (平滑滚动被禁用)

您可以帮我提高的DataGridView 性能?

解决方案

我最近与的DataGridView一些缓慢的问题和解决方案是下面的code

 公共静态无效DoubleBuffered(此的DataGridView DGV,布尔设置)
{
    键入dgvType = dgv.GetType();
    的PropertyInfo PI = dgvType.GetProperty(DoubleBuffered
          BindingFlags.Instance | BindingFlags.NonPublic可);
    pi.SetValue(DGV,设置,NULL);
}
 

原来对的DataGridView 对象双缓冲。只需拨打 DoubleBuffered()您DGV。希望它能帮助。

编辑:我可能已经走了这么得到了这一关,但我不能搜索原来现在所以这只是强调,code是不是我的<。 / P>

(sorry for bad English)

I have a big problem with performance of DataGridView when it re-paints.

I'm using a DataGridView to show logs from an external application stream. Messages from the stream come in with a high frequency (less than 1 ms). If I add new row to the DataGridView immediately when each new message comes, the DataGridView doesn't have time to re-paint itself before the next message comes.

A possible solution is to use a queue to collect messages and re-paint DataGridView every 100 ms with messages from queue. This is good but the DataGridView blinks when it auto-scrolls to the last row. (Smooth scroll is disabled)

Can you help me to improve DataGridView performance?

解决方案

I recently had some slowness issues with DataGridView and the solution was the following code

public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
    Type dgvType = dgv.GetType();
    PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
          BindingFlags.Instance | BindingFlags.NonPublic);
    pi.SetValue(dgv, setting, null);
}

It turns double buffering on for DataGridView objects. Just call DoubleBuffered() on your DGV. Hope it helps.

Edit: I might've gotten this off SO, but I can't search for the original right now so this is just to emphasize that the code isn't mine.

这篇关于如何提高DataGridView的绘画表现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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