I understand sorting rules may be more complex than comparison of two objectsthat implement IComparable interface. How can it be done?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
life guruPosted May 17, 2016, 2:50 PM
I use dapfor wpf gridcontrol and all sorting are simple. To solve this problem, ICustomSort interface has been implemented.
C#
class RatingComparer : ICustomSort
{
public int Compare(Row row1, Row row2, string fieldId, object value1, object value2, int defaultResult)
{
int result = defaultResult;
if (fieldId == "Rating")
{
string rating1 = (string) value1;
string rating2 = (string) value2;
if(!string.IsNullOrEmpty(rating1) && !string.IsNullOrEmpty(rating2))
{
//compare two ratings: rating1 > rating2 => result is positive
// rating1 == rating2 => result = 0
// rating1 < rating2 => result is negative
//result = ...
}
}
return result;
}
}
grid.CustomSort = new RatingComparer();
Bhuvanesh MohankumarPosted May 17, 2016, 5:28 AM
Please find the below link for more data sorting with screen shot & code explained.
http://www.dapfor.com/en/wpf-suite/gridcontrol/tutorial/tutorial-part9