小编Hun*_*uan的帖子

在C#中向ListView添加项目太慢

我想将项目添加到listview控件.这是一些代码:

    this.lView.ListViewItemSorter = null;
    ListViewItem[] lvitems = new ListViewItem[ListMyObjects.Count];
    int index = 0;
    foreach (MyObject object in ListMyObjects)
        {
            ListViewItem item = new ListViewItem();               
            item.Text = object.Name;
            lvitems[index++] = item;
        }
    this.lView.BeginUpdate();
    this.lView.Items.AddRange(lvitems); // Slow in here with debugger
    this.lView.EndUpdate();
Run Code Online (Sandbox Code Playgroud)

我只添加了大约1000个项目,但速度非常慢.它花了大约15秒完成.为什么有人知道原因?预先感谢.

编辑:

我以前定制过listview.

public partial class MyListView: ListView
{        
    public MyListView()
    {
        InitializeComponent();
        this.View = View.Details;
        this.FullRowSelect = true;
        this.DoubleBuffered = true;
    }
    private bool mCreating;
    private bool mReadOnly;
    protected override void OnHandleCreated(EventArgs e)
    {
        mCreating = true;
        base.OnHandleCreated(e); …
Run Code Online (Sandbox Code Playgroud)

c# listview winforms

5
推荐指数
0
解决办法
3219
查看次数

标签 统计

c# ×1

listview ×1

winforms ×1