views:

489

answers:

3

I'm working on a media library mock-up and I have a database of songs (over 9,000 tracks) that I want to display and make sortable. I'm not sure which GUI control would be best to use and I am not sure how it would be best to add all of the entries to the control.

Obviously using a listview and adding each entry one at a time takes a long time. Currently, the database is returning all of the tracks in an array of media objects (mediaEntry[] - a struct I defined). I don't know much about .NET's databinding system and any performance benefit that may bring.

The database is also searchable so I'll be changing the information displayed in the GUI control depending on the search terms.

+6  A: 

Something like DataGridView or ListView in "virtual mode" should work well; this avoids the need to process all the data up-front.

however - I doubt that mediaEntry should be a struct - sounds like a class to me. It is very rare you write a struct in .NET

Marc Gravell
Eh, doesn't make much of difference (struct or class) as it's always passed around in the same array - correct?
Mr. Pig
Every time it is fetched out of the array it is cloned (as it is a mediaEntry[]), which could have cost - but the bigger issue is simply semantics; it should behave as an object, not a value.
Marc Gravell
FYI - this binding is much easier in WPF than the forms demo linked. Although sometimes the ListView in WPF has a bad habit of dropping out of the default virtualization mode. If it does, it's easy to force it to do so: <ListView> <ListView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate> </ListView.ItemsPanel> // other listview stuff </ListView>
patjbs
Fair enough. Made the change.
Mr. Pig
Brian Noyes' book "Data Binding with Windows Forms 2.0" has a good example of using Virtual Mode in a DataGridView where he renders a million items effortlessly. [p233]
Jonathan Webb
+1  A: 

The Listview control has a virtual mode, where you supply the viewable data on demand. Its actually easier to use than it sounds. Checkout the VirtualMode property and the RetrieveVirtualItem event.

Tim Jarvis
A: 

You may want to give ObjectListView a try. It's very handy to use and has excellent performance when used appropriately.

Note: I'm not the developer of this library, I'm advertising it just because I used it in one of my projects.

Sorin Comanescu