ListBox Filtering

J

jp2msft

I've got a ListBox on my Visual Studio C# form with several entries (14,000).

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?

Code:
private void Filter(string value)
{
for (int i = ListView1.Items.Count - 1; -1 < i; i--)
{
if (ListView1.Items.SubItems[1].Text.StartsWith(value) == false)
{
ListView1.Items.Remove();
}
}
ListView1.Refresh();
}
 
M

Mr. Arnold

jp2msft said:
I've got a ListBox on my Visual Studio C# form with several entries
(14,000).

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?


You don't load 14,000 entries into a listbox control. <smile>

You load subsets of data in this case by making a method the filters the
entries that would be in an array as an example and load the subset of data
into the listbox.

You must give the illusion of speed and 14,000 entries being loaded into a
listbox and trying to filter on the contents of the listbox is not it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top