joe_pool_is
Contributor
I've got a ListBox on my form with lots of data in it (14000 entries).
I have to put a search field on the form. As text is entered into the search field, I want the ListBox to remove entries that do not match. Sounds simple enough, but it is really taking a long time! I started running it before opening my web browser, and now (with typing this message, I'm about to go over and hit a breakpoint) it is at ... 12687 entries, and all I've entered is one character into my filtering TextBox.
Why is my version taking so long?
What can I do to speed it up?
I have to put a search field on the form. As text is entered into the search field, I want the ListBox to remove entries that do not match. Sounds simple enough, but it is really taking a long time! I started running it before opening my web browser, and now (with typing this message, I'm about to go over and hit a breakpoint) it is at ... 12687 entries, and all I've entered is one character into my filtering TextBox.
Why is my version taking so long?
What can I do to speed it up?
C#:
private void Filter(string value)
{
for (int i = ListView1.Items.Count - 1; -1 < i; i--)
{
if (ListView1.Items[i].SubItems[1].Text.StartsWith(value) == false)
{
ListView1.Items[i].Remove();
}
}
ListView1.Refresh();
}