我无法阻止ListView控件闪烁 [英] I can't stop ListView Control from flickering
本文介绍了我无法阻止ListView控件闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用listView控件大约每秒钟显示从数据库中提取的数据,并添加大约5-10项.每次将新数据添加到listView时,它都会闪烁.我似乎无法弄清楚如何停止闪烁.
任何建议/解决方案我将非常感谢!
这是一段示例代码,以演示如何尝试阻止闪烁,但仍然无法正常工作.
样本代码:
for ( int i = 0 ;我< 500 ; i ++)
{
ListViewItem lvi = 新 ListViewItem(i.ToString(),-1);
lvi.SubItems.Add((i * 2 ).ToString());
lvi.SubItems.Add((i * 3 ).ToString());
ListView1.Items.Add(lvi);
}
for ( int i = 0 ; i < 500 ; i ++)
{
ListViewItem lvi = this .ListView1.Items [i];
lvi.ImageIndex = i;
ListView1.Invalidate(lvi.Bounds);
更新();
}
解决方案
您是否尝试过在所有者上调用SuspendLayout(),然后添加您的商品,然后调用ResumeLayout()而不进行更新且没有无效
ARopo答案的替代方法是使用 ^ ]和ListView.EndUpdate()
方法成对使用.
一些WidowsForms控件都具有这些方法,因此始终值得检查.
Hi,
I''m using the listView control to display data pulled from a database approx every sec and adding approx 5-10 items. Each time new data is added to the listView it flickers. I can''t seem to figure out how to stop the flickering.
Any advice/solutions would me very much appreciated!
Here''s a sample piece of code to demonstrate how I''ve been trying to stop the flickering but it''s still not working.
SAMPLE CODE:
for (int i = 0; i < 500; i++)
{
ListViewItem lvi = new ListViewItem(i.ToString(), -1);
lvi.SubItems.Add((i * 2).ToString());
lvi.SubItems.Add((i * 3).ToString());
ListView1.Items.Add(lvi);
}
for (int i = 0; i < 500; i++)
{
ListViewItem lvi = this.ListView1.Items[i];
lvi.ImageIndex = i;
ListView1.Invalidate(lvi.Bounds);
Update();
}
解决方案
Have you tried calling SuspendLayout() on the owner, then add your item then call ResumeLayout() no update and no invalidate
An Alternative to ARopo''s answer is to use the ListView.BeginUpdate()[^] andListView.EndUpdate()
methods in pairs.
Several of the WidowsForms controls have these methods, so it''s always worth checking.
这篇关于我无法阻止ListView控件闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文