My WinForms UI contains a tab control with two tab pages. On one tab, I need to display a list of up to 100,000 strings in a manner that allows my users to add, edit and delete strings in the list. On the second tab, I need to display a “read-only” copy of the strings from the first tab. I also need controls on the second tab that allow the user to copy strings from the “read-only” list into a second unrelated list.
I currently have the 100k strings in an array and my first thought was to use a listbox to display them. I can loop through the array and individually add the strings to a listbox on the first tab. That takes about 1.5 seconds to display if I use SuspendLayout() and BeginUpdate(). Unfortunately, there are vertical scrollbar issues when I add more than ~65k items to a listbox (apparently this is a bug in the listbox control that was introduced around the time of Vista). Since the string data is not bound to the listbox, I’m basically adding the same entire data set to another listbox on my second tab. Now if I launch my app, wait for the strings to be added to the listboxes and then try to select the second tab, the performance is very slow waiting for the second tab to become responsive. I’m assuming this is related to the volume of data in the listboxes. Anyway, once the second tab becomes responsive, I can switch between the two tab pages with much less of a delay.
As a test, I tried binding both listboxes to the array but it didn’t make any difference from a performance standpoint. And the scrolling bug is probably going to make the listbox an unusable option for me anyway. So then I tried the listview control in list mode with a single hidden column header. The performance isn’t much different when I add the string data as individual ListViewItems. I was going to try binding two listview controls to my array but it looks like the listview control doesn’t support design-time data binding and I’m not sure that it would make much difference if I were to try to implement it myself.
I know 100,000 strings (max) is a lot of data for a user to process but it’s a requirement that the use be able to see all of the string data in the application (and the worst case is the first thing my QA team will start testing with!). Is there another control that would lend itself to this volume of data and the functionality that I need? Or am I just going about this all wrong?
I dont think you will ever help the user by providing more than 50 strings at a time for the user. With a DataGridView you could load on demand which is better suited for this. See VirtualMode. Or else you could load items to listbox manually on user input, which is way better. Try to convince the customer on that front that it will only do more harm than good to have 100k strings at a time.
I do think DataGridViews will be too much to display simple strings, but provides you the flexibility to provide more features in future (like more columns etc). As to how to populate that large amount of data to a gridiview, do a search, there are plenty of threads on it. Here are two good starters
http://www.codeproject.com/Articles/38735/Load-a-billion-rows-in-a-DataGridView
What's better to use: a DataGrid or ListView for displaying large amounts of data?
As I said the best option is to rethink the design..