0

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!

6
  • 2
    Can you have the database sort the records for you? Commented Apr 15, 2014 at 14:24
  • 3
    Are you using MVVM architecture? If so then you can just sort your ObservableCollection<> using Linq for exemple. Sorting inside the view by removing and replacing items will be a bit slow because of lifetime of UI elements. Commented Apr 15, 2014 at 14:24
  • @Didier By MVVM do you mean entity framework and the ADO.NET database model? If so then no I am not using that for this project, I'm trying to explore alternative methods. Commented Apr 15, 2014 at 14:33
  • @AdilB I could but i would prefer the processing of data to occur within the code itself that way even if I were to use this interface with someone else's database which I did not have any control over it would work just fine. Commented Apr 15, 2014 at 14:36
  • 1
    No MVVM are the base concepts of WPF. It's the way to implement your UI and to communicate with your model. Implementing INotifyPropertyChanged, Bindings, Commands, ... Commented Apr 15, 2014 at 14:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.