ListView Sort ProgressBar

Ice725

Freshman
Joined
Apr 19, 2004
Messages
31
I have a ListView with many ListViewItems. I have coded the ColumnClick event to sort the ListView. I got the code from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/listviewsort.asp

Since I have many ListViewItems, it takes a few seconds to sort. During this time, the Form appears to freeze. Is it possible to implement a ProgressBar to show the status of the Sort?

I have successfully created a ProgressBar, but I'm not sure how to synchronize the Sort with the ProgressBar value. Can someone get me started?
 
Two things. First to get the form to not freeze you will need to use a background worker thread (documentation for .Net 2.0. You'll have to use a regular thread if use 1.1). That step is optional and will just allow the form to repaint and stay updated as you are doing a heavy sort operation.

As far as getting progress, one way I have done this is to give a pointer to my progress bar to the IComparer Class I created to sort the listview data. I know that the Sort() method uses QuickSort algorithm and that QuickSort takes on average O(n*Log(n)) time to complete. So, I set my progress bar max to n*Log(n), where n = number of rows in the listview, and incremented the progress bar each time the IComparer was called.

You'd probably want to use either a delegate (single threaded) or event (if you end up multi threading) to reference the progress bar instead of referencing it directly (I did it the lazy way).

The O(n*Log(n)) is just an estimation of how long it the sort will take. At worst it will tkae O(n^2) which means you're progress bar may finish and the user has to wait a little longer for the actual sort to finish.

This will work, but I'm not fully satisfied with this solution. Does anyone else have a better solution to this? I would be interested to hear..
 
Rather than guessing the time remaining you could use an alternative type of progress bar, similar to the one you see when Windows XP boots. This informs the user that progress is being made, but doesn't give an estimation of how far through the process it is. It basically allays the users fears that the program has frozen. However I suspect that to get this working you will still need the seperate thread.
 
Cags said:
Rather than guessing the time remaining you could use an alternative type of progress bar, similar to the one you see when Windows XP boots. This informs the user that progress is being made, but doesn't give an estimation of how far through the process it is. It basically allays the users fears that the program has frozen. However I suspect that to get this working you will still need the seperate thread.
u can use a gif file, showing work...
 

Attachments

gif will work, but as a last resort in my opinion.

A gif is very web-like and will definately work. The marquee style progress bar is free with .Net 2.0, so why not just use that? If you are using .Net 1.1, here's a link on how to set up your own marquee progress bar.

I am using a gif instead of a statusstrip progressbar in an app I'm working on right now because I didn't have time to figure out how to get marquee style to work with that particular progress bar. Unlike .net 1.1, the status strip progess bar is completely different than the regular progress bar. I'll take a look at that again and see if I can figure it out or maybe if I overlooked something before (I was under a time crunch to churn something out).
 
Back
Top