Again great information. :)
I did as you said, now the hurdle is, the compare method isnt getting called even though I did change the style.cellvaluetype = NumericSortString(my custom type).
I did the change in the querycellinfo event handler:
if( e.Style.CellValueType == typeof(System.String))
e.Style.CellValueType = typeof(NumericSortString);
e here is the GridQueryCellInfoEventArgs and when I debug through it, this step does get called for every cell on the grid.
Anything I missed here?
Thanks.
zheng
>Hi Zheng,
You need to create a class that implements IComparable interface and overrides CompareTo() method from that class to change the sorting behavior. And then you can add a column of that type to your datatable. When you sort a dataview based on that datatable by the column, It will use your IComparer class. Below is a code snippet
Public class CustomType : IComparable
{
public CustomType(string s)
{
Value = s;
}
int IComparable.CompareTo(object obj)
{
int iv1 = System.Convert.ToInt32( this.Value);
int iv2 = System.Convert.ToInt32( (CustomType)obj).Value));
return iv1.CompareTo( iv2);
}
private string _Value;
public string Value { set { _Value = value; } get { return _Value; } }
public override string ToString()
{
return _Value;
}
}
DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2", typeof(CustomType));
dt.Rows.Add(new object[] {"a", new CustomType("111") });
dt.AcceptChanges();
Here is a forum thread that discuss with the GridData.SortByColumnMethod.
http://www.syncfusion.com/support/forums/message.aspx?&MessageID=7562Best regards,
Haneef