473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ListView Filtering

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.

The data comes from a data table, but we add extra "readability" fields, so
it is not something that is data bound.

Why is my version taking so long?

What can I do to speed it up?

Example 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();
}

Aside: I tried using Visual Studio's Auto Complete setting, but it didn't
work. Looking up the help, it told me that the maximum number of Auto
Complete values depends on the OS (no other information). I presume I was
over running the buffer, so it crapped out on me.

Jun 27 '08 #1
2 5557
jp2msft wrote:
I've got a ListBox on my form with lots of data in it (14000 entries).
Wow, I would say first off don't do that, if you can you should try and
re-architect things so that you don't store that many items in GUI
controls, its simply not good design.

If you really and truely just have to have that much data stuffed into
a listview (and trust me you shouldn't) then put the ListView in
Virtual mode and just pass it the data it wants to display from a
cached list, rather than filter items out of the list (as you found out
the hard way, that is way to slow), just pass it those items that it
needs to satisfy your filter and how many items its displaying.

More info here.

http://msdn.microsoft.com/en-us/libr...ms.listview.vi
rtualmode.aspx#Mtps_DropDownFilterText

Cheers Tim.

--

Jun 27 '08 #2
Wow, Mr. Jarvis! That is a good article! I'm using Framework 2.0, but the
tutorial page for the Framework 3.5 is *much* better!

I'm going to start working on it right now!

"Tim Jarvis" wrote:
jp2msft wrote:
I've got a ListBox on my form with lots of data in it (14000 entries).

Wow, I would say first off don't do that, if you can you should try and
re-architect things so that you don't store that many items in GUI
controls, its simply not good design.

If you really and truely just have to have that much data stuffed into
a listview (and trust me you shouldn't) then put the ListView in
Virtual mode and just pass it the data it wants to display from a
cached list, rather than filter items out of the list (as you found out
the hard way, that is way to slow), just pass it those items that it
needs to satisfy your filter and how many items its displaying.

More info here.

http://msdn.microsoft.com/en-us/libr...ms.listview.vi
rtualmode.aspx#Mtps_DropDownFilterText

Cheers Tim.

--

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: keith | last post by:
In a ListView control (two columns), I added a few ListView items. ListView listview=new ListView(); listview.Parent=this; listview.View=View.Details; listview.Columns.Add...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
4
by: Scott H | last post by:
If I have a Listview (in report mode) and theres several hundred items in it, is there any way programatically, to automatically scroll to the last item...Eg. the same thing that would happen if...
5
by: Charles Law | last post by:
Some of the eagle-eyed amongst you will spot this as a direct follow on from my earlier post about critical timing in .NET. I want to use a ListView to display my output (instead of the sluggish...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
11
by: MarkTingson | last post by:
I am creating a VB6 project that uses listview as my datagrid. So far I am successful in adding, editing, deleting and refreshing the table (I'm talking about the listview). My problem now is to do...
4
by: kelvin.koogan | last post by:
Using VS2005, C++, .NET I have a ListView with OwnerDraw=true, Details view, that I am using to display messages in real-time. Ideally I want to scroll down to the bottom, i.e. most recent...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.