Home All Groups Group Topic Archive Search About

Sorted array suggestions

Author
7 Apr 2006 11:37 AM
al jones
I need to create a collection of data and I'm not sure what approach to
take - any suggestions appreciated.

For example, using mp3's, If I collect:
1) song title
2) file name
3) producer
4) artist
5) bit rate
and the user wants to see one list sorted by artist and another by title
what's the general concensus for the structure to use.  I realize a
database would be most efficient but the program I'm working with has none,
and I'm not sure I want to create one given the 'fluidity' of a users
'collection' of song.

As I understand it array.sort expects a one dimensional array.  I don't see
how an array of a structure could be used to sort by various 'columns'.

Hope this is sufficiently clear.  Suggestions??

Thanks //al

Author
7 Apr 2006 1:25 PM
AMercer
Show quote Hide quote
> I need to create a collection of data and I'm not sure what approach to
> take - any suggestions appreciated.
>
> For example, using mp3's, If I collect:
> 1) song title
> 2) file name
> 3) producer
> 4) artist
> 5) bit rate
> and the user wants to see one list sorted by artist and another by title
> what's the general concensus for the structure to use.  I realize a
> database would be most efficient but the program I'm working with has none,
> and I'm not sure I want to create one given the 'fluidity' of a users
> 'collection' of song.
>
> As I understand it array.sort expects a one dimensional array.  I don't see
> how an array of a structure could be used to sort by various 'columns'.

I suggest you use a ListView control.  You can have columns for your data,
and you can arrange to sort the display on any of the columns.  You would
have to write some code to populate the ListView with data (maybe from one or
more external files).
Author
7 Apr 2006 1:27 PM
Chris Dunaway
If you have a structure containing all the mp3 info, you could create a
class that implements the IComparer interface and in the CompareTo
method, you would provide the logic to compare two of your structure
variables.

You could add a property to the class to indicate which field to sort
on.  Then when you call the Array.Sort, you pass in an instance of your
comparer class.
Author
7 Apr 2006 9:19 PM
Cerebrus
I second Chris' suggestion. It might be a little complicated to
implement, but once done, it will work the best, and give high
performance while sorting is performed.

Personally I have found a huge performance difference between sorting
data using a control's built-in sort method and sorting data by using
an IComparer.

Regards,

Cerebrus.
Author
9 Apr 2006 9:38 AM
al jones
On 7 Apr 2006 06:27:30 -0700, Chris Dunaway wrote:

> If you have a structure containing all the mp3 info, you could create a
> class that implements the IComparer interface and in the CompareTo
> method, you would provide the logic to compare two of your structure
> variables.
>
> You could add a property to the class to indicate which field to sort
> on.  Then when you call the Array.Sort, you pass in an instance of your
> comparer class.

Thank you both, one is over my head at the moment and the other I'm not
sure about.  Ended up just stuffing them as concatenated strings into an
array, calling sort and now off to figuring out how to 'print' them to a
richtextbox.  Holding onto your information as time passes and my
expertise, hopefully, improves.   //al