更新ListView的项目和子项目具有定时 [英] Update listview's items and subitems with a timer

查看:244
本文介绍了更新ListView的项目和子项目具有定时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新部分或全部我的ListView的项目和子项目内容具有定时(1秒刷新),但在ListView闪烁每一秒。有时,子项都重新绘制过程中丢失。因为我的列表视图中包含的数据是随时可能改变,我用一个定时器

I would like to update some or all of my listview's items and subitems contents with a timer (1 second refresh) But the listview flicker each one second. Sometimes the subitems are lost during redrawing. Because my listview contains data that is to be likely changed anytime, I use a timer.

代码:
我放在计时器的Tick方法此功能

Code: I put this function in the timer's Tick method

void Refresh()
{
   foreach(string s in lsttring)
   {
      lv.items.add(s);
      lv.items[i].subitems.add(i);
   }
}



我只希望项目的内容(项目文本和子项文本),这些改变将不整列表视图的计时器滴答而变化。

I expect only items content (item text and subitem text) that are changed will be changed not the whole listview along with the timer tick.

推荐答案

ListView控件支持双缓冲,它该DoubleBuffered属性设置为本地控制的LVS_EX_DOUBLEBUFFER风格标志映射。这是很有效的,但你不能将其直接,因为它是一个受保护的财产。添加一个新类到您的项目并粘贴如下所示的代码。编译。从工具箱到窗体顶部掉落新的控制,换旧人。

The ListView control supports double buffering, it maps the DoubleBuffered property to the native control's LVS_EX_DOUBLEBUFFER style flag. It is quite effective but you can't get to it directly since it is a protected property. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form, replacing the old one.

using System;
using System.Windows.Forms;

class BufferedListView : ListView {
    public BufferedListView() {
        this.DoubleBuffered = true;
    }
}

这篇关于更新ListView的项目和子项目具有定时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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