How to speed adding items to a ListView?

前端 未结 5 465
温柔的废话
温柔的废话 2020-12-04 11:47

i\'m adding a few thousand (e.g. 53,709) items to a WinForms ListView.

Attempt 1: 13,870 ms

foreach (Object o in list)
         


        
5条回答
  •  Happy的楠姐
    2020-12-04 12:19

    I have the same problem. Then I found it's sorter make it so slow. Make the sorter as null

    this.listViewAbnormalList.ListViewItemSorter = null;
    

    then when click sorter, on ListView_ColumnClick method , make it

     lv.ListViewItemSorter = new ListViewColumnSorter()
    

    At last, after it's been sorted, make the sorter null again

     ((System.Windows.Forms.ListView)sender).Sort();
     lv.ListViewItemSorter = null;
    

提交回复
热议问题