Update listview's items and subitems with a timer

前端 未结 2 1266
时光说笑
时光说笑 2020-12-12 04:17

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 subi

2条回答
  •  忘掉有多难
    2020-12-12 04:45

    Try this:

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

    In this manner you update all the items and listview will be refreshed only at the end of this operation.
    From Microsoft:

    ...if you want to add items one at a time using the Add method of the ListView.ListViewItemCollection class, you can use the BeginUpdate method to prevent the control from repainting the ListView every time that an item is added. When you have completed the task of adding items to the control, call the EndUpdate method to enable the ListView to repaint. This way of adding items can prevent flickered drawing of the ListView when lots of items are being added to the control.

提交回复
热议问题