1

I have a ListView-Control which holds several entries (about 300). When I open it, it starts up pretty quick. I do some things and call the btnRefresh_Click-Button event to fill data into the ListView.

public ListWords()
{
    InitializeComponent();

    lvwColumnSorter = new ListViewColumnSorter();

    this.lstWords.Visible = true;
    this.btnCheckLinks.Visible = true;
    this.lstWords.ListViewItemSorter = lvwColumnSorter;

    btnRefresh_Click(null, new EventArgs());
}

The event does this:

public void btnRefresh_Click(object sender, EventArgs e)
{
    lstWords.Items.Clear();

    foreach (var word in WordData.AllWords)
    {
        string[] lvi = { 
            word.Id.ToString(), word.Name, word.Link,
            word.Status, word.Count.ToString() 
        };

        lstWords.Items.Add(new ListViewItem(lvi));
   }
}

So far so good. But if I actually PRESS the button to manually refresh the ListView, it takes around 4 to 5 seconds! I'ts even faster if I close the form and open a new one, then the refreshed data appears in an instant.

What is the cause for this behaviour? I can't figure out what the difference is between calling it programmatically in the constructor and calling it manually by a button press event. Thanks in advance!

FRules
  • 739
  • 1
  • 10
  • 20
  • 2
    Id remove your sorter, run BeginUpdate on it, and EndUpdate, that would probably speed it up a lot for a refresh – BugFinder Mar 21 '16 at 11:16
  • 4
    See [this](http://stackoverflow.com/q/9008310/1997232). – Sinatr Mar 21 '16 at 11:27
  • The sorter was the problem. In the Refresh-Event I set it temporary to null, build up the new list using Begin- and EndUpdate and afterwards I set it again. This was a huge performance boost, thanks! – FRules Mar 21 '16 at 12:12

0 Answers0