mulitiple sorting in a list.

S

Sugandh Jain

Hi,

I want to sort a collection of items on two columns, one after other as it
happens for the select query in the Sql server.

i.e.
Say I have a collection, of
Emp ID, designation, salary


so, using sorted list, i want them sorted first by designation , then within
the group of same designation, sorting on salary.

I am using, .net 2.0 and a sortedBindingList , i have made the class which
implements sorted on 1 property, but now, how to go about the second
property.


Regards,
Sugandh
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

If you class implement IComparable you can do it, inside the CompareTo
method you can do the comparision using both properties

kind of:

int CompareTo( object o )
{
mytype t= (mytype)t;
if ( prop1==t.prop1)
{
if ( prop2 == t.prop2 ) return 0;
if ( prop2 > t.prop2 ) return 1;
return -1;
}
if ( prop1 < t.prop1 ) return -1;
return 1;


I hope you get the idea
 

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