Reputation: 141
I am fairly new to C# and have been stuck on a problem for a while now.
I have a program which contains a list view, the list view can sometimes read, populate and sort over 10,000 records from a sql server database. I am currently trying to optimise my code in order to improve overall run time and efficiency so decided to play around with the sorting method.
From my research and past knowledge I know that there are a large number of sorting algorithms and the one that I am most interested in is quick sort, from what I understand it is not the most accurate but it is as the name implies, the quickest.
One way I was thinking of implementing a quick sort to the list view is by somehow inserting all of the listviewitems (records) into a generic list then sorting them within the list using a lambda expression and then adding all of them items back into the list view. This should prevent the code jumping back and forth between the IComparer class and the list view to sort the items.
TLDR:
How can I insert all listviewitems into a List which can then be used with a quick sort algorithm? Is there an better solution for sorting a listview in the shortest amount of time?
Any help would be much appreciated, thanks in advance!
Upvotes: 0
Views: 420
Reputation: 708
10000 records can be a lot of data to dump to the screen at once. Consider server side pagination.
http://www.codeproject.com/Articles/485531/ASP-NET-Pagination
The provided example is for ASP.NET, but you should be able to use similar methodology for MVC and winforms.
Upvotes: 1