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!