Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - ListBox Filtering

Reply
 
Old 06-04-2008   #1 (permalink)
jp2msft


 
 

ListBox Filtering

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[i].SubItems[1].Text.StartsWith(value) == false)
{
ListView1.Items[i].Remove();
}
}
ListView1.Refresh();
}

My System SpecsSystem Spec
Old 06-04-2008   #2 (permalink)
Mr. Arnold


 
 

Re: ListBox Filtering


"jp2msft" <jp2msft@xxxxxx> wrote in message
news:ECE4DB6F-A650-4A9D-8D76-CD92250A894A@xxxxxx
Quote:

> 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.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Set Listbox Value .NET General
Easy to get handle from listbox. How to get listbox from handle? .NET General
Listbox PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46