在更新过程控制中的WinForms闪烁(如DataGridView中) [英] Flickering during updates to Controls in WinForms (e.g. DataGridView)

查看:116
本文介绍了在更新过程控制中的WinForms闪烁(如DataGridView中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序有一个DataGridView控件,选定对象显示的数据。当我选择一个不同的对象(在上面的组合框),我需要更新的网格。不幸的是不同的对象具有完全不同的数据,甚至不同的列,所以我需要清除所有现有的数据和列,创建新列,并添加所有行。当这样做时,整个控制闪烁可怕和它需要年龄。有没有一种通用的方法来得到一个更新的状态,因此不会重新绘制本身,然后重新绘制它后,我完成所有更新的控制?

In my application I have a DataGridView control that displays data for the selected object. When I select a different object (in a combobox above), I need to update the grid. Unfortunately different objects have completely different data, even different columns, so I need to clear all the existing data and columns, create new columns and add all the rows. When this is done, the whole control flickers horribly and it takes ages. Is there a generic way to get the control in an update state so it doesn't repaint itself, and then repaint it after I finish all the updates?

这当然是可能的的TreeView:

It is certainly possible with TreeViews:

myTreeView.BeginUpdate();
try
{
    //do the updates
}
finally
{
    myTreeView.EndUpdate();
}

有没有一种通用的方法与其他控件,DataGridView中尤其是这样做呢?

Is there a generic way to do this with other controls, DataGridView in particular?

更新:对不起,我不知道我是很清晰。我看到的闪烁,因为单一的编辑后,控制被重新绘制在屏幕上,这样你就可以看到滚动条萎缩等。

UPDATE: Sorry, I am not sure I was clear enough. I see the "flickering", because after single edit the control gets repainted on the screen, so you can see the scroll bar shrinking, etc.

推荐答案

而不是在同一时间将数据网格之一行,使用 DataGridView.Rows.AddRange 方法来一次添加的所有行。这应该只更新一次显示。还有一个 DataGridView.Columns.AddRange 为列做同样的。

Rather than adding the rows of the data grid one at a time, use the DataGridView.Rows.AddRange method to add all the rows at once. That should only update the display once. There's also a DataGridView.Columns.AddRange to do the same for the columns.

这篇关于在更新过程控制中的WinForms闪烁(如DataGridView中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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