joe_pool_is Posted June 4, 2008 Posted June 4, 2008 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? 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(); } Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted June 4, 2008 Administrators Posted June 4, 2008 14,000 entries is an awful lot for a listbox, is there any way this could be reduced? How is the listbox populated? If the data is in a data table you could bind to a data view instead and use it's filtering capabilities. Would it be possible to wait until a character or two have been typed and then bind to items that match rather than removing non-matches? If you are using VS 2005 or higher you could try using a text box and populate the auto complete list with your 14,000 strings. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted June 4, 2008 Author Posted June 4, 2008 Using VS 2005. I tried using the Auto Complete setting (set AutoCompleteMode to SuggestAppend, AutoCompleteSource to CustomSource, and provided an AutoCompleteCustomSource after collecting the data), but Auto Complete didn't seem to do anything. Looking up Auto Complete, MSDN told me that the maximum number of Auto Complete values depends on the OS (rather vague). I presumed I was over running the buffer and it crapped-out on me (technical term). The data _does_ come from a table, but it has been messaged for readability where I have added additional columns. I can't seem to find out how to databind something that also has manually added columns. Lots of examples! ...but not many that step outside of the realm of automation. Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.