We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GridDataSortColumn CustomComparer doesn''t work

Thread ID:

Created:

Updated:

Platform:

Replies:

98971 Apr 13,2011 04:49 AM Apr 19,2011 04:35 AM WPF 2
loading
Tags: GridControl
berthet
Asked On April 13, 2011 04:49 AM

Hello,

I try to make sort numeric on datacolumn whith dataType = typeof(string); because some rows are empty, adn the others are fill witrh numerics values.

So, i try to implement a CustomComparer on a column. But the compare function was never called.

void Table_SortColumnsChanging(object sender,GridDataSortColumnsChangingEventArgs args)
{
foreach (var item in args.AddedItems)
{
if (item.ColumnName.Equals("LABEL_TAPP_COLUMN_NAME"))
{
item.CustomComparer = new NumericSort();
item.SortDirection = ListSortDirection.Ascending;
}
}
}


berthet
Replied On April 13, 2011 04:52 AM

Excuse me the message was post before it was finish.

public class NumericSort : System.Collections.Generic.Comparer
{

public NumericSort():base()
{
System.Diagnostics.Trace.WriteLine("NumericComparer: creation");
}

public override int Compare(object x, object y)
{
System.Diagnostics.Trace.WriteLine("NumericComparer: Compare");
string sX = x.ToString();
string sY = y.ToString();

if ((sX != string.Empty) && (sY != string.Empty))
{
// System.Diagnostics.Trace.WriteLine(string.Format("NumericComparer: Compare {0} , {1}", sY, sY));
int ix = int.Parse(sX);
int iy = int.Parse(sY);

// return ix - iy;
// * If they are both null, return 0
//* If x is null but not y, return -1 (x < y)
// * If y is null but not x, return 1 (x > y).
if (ix < iy)
{
return -1;
}
else if (ix < iy)
{
return 1;
}
else
{
return 0;
}

}
else
{
if (sX == string.Empty && sY == string.Empty)
{
return 0;
}
else if (sX == string.Empty)
{
// int iy = int.Parse(sY);
// return - iy;
return -1;
}
else
{
// int ix = int.Parse(sX);
// return ix;
return 1;
}
}


}
}


Constructor was call, but compare function no.

Have you some example on CustomComparer ?



Rajasekar [Syncfusion]
Replied On April 19, 2011 04:35 AM

Hi Berthet,

Thanks for your update.

We have prepared the sample based on your requirement, please find the sample in the following location,

Sample: < http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=CustomSorting_Sample465204710.zip >

Please let us know if you have any queries.

Thanks,
Rajasekar




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;