Reputation: 213
For a class assignment, I am supposed to populate a Listbox with a list of anagrams generated from a character string, up to 8 characters. The instructions are very clear that I must use a Listbox. I have done enough research to know that a Listbox control is far from ideal for a data set this large. However, my hands are tied, as this is what my professor wants.
For sets generated from smaller strings, there is no problem scrolling through my Listbox once my list is generated. Once the entry string reaches 8 characters, I am unable to scroll though the Listbox to view the entries, as 40,320 strings have been found (Distinctions between words and non-words are not made, so there are 8! anagrams generated). In fact, the entire form freezes.
As the anagrams are generated, I add them to an ArrayList and then bind the data to the Listbox after returning from the function. I have tried various methods for getting the data to the Listbox (such as adding them directly to the Listbox inside the anagram function and using a foreach), but the same performance issue persists because the number of entries is just too large. I have also debugged enough to know that the performance issue comes from getting the data into the Listbox; commenting out this section allows the code to perform all other functions without issue.
Is there anything I can do to manage a Listbox this large to allow the user to scroll without freezing the screen?
Upvotes: 0
Views: 615
Reputation: 11
Is the ListBox's Sorted property set to True? If so, try setting it to False before you begin adding items, then set it to True once the ListBox has been populated. You can also look into calling the BeginUpdate() and EndUpdate() methods to suppress repainting the ListBox while it is being populated.
Upvotes: 1