Sorted array suggestions

A

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
 
G

Guest

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).
 
C

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.
 
C

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.
 
A

al jones

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top