I have a grid that I want to display values that are sortable. The values come from the DB as a string, but they only contain numbers. If I use CellValueType = GetType(Int16), and try to sort by clicking on the header, they order is not always correct. For example I get 7,6,5,4,3, 10, 11,12. I did use CInt() to change the value to an int in my code where I add the item to the grid, but this seems like extra work. Shouldn't using the CellValueType take care of this for me.
In the 18.104.22.168 private build we add some changes so that you can specify a custom comparer.
With these changes you can then do the following:
1) Call SortByColumn with custom comparer object
this.gridControl1.Data.SortByColumn(col,(ListSortDirection)this.gridControl1[0, col].Tag, new CustomComparer());
2) This is how such comparer object can look like.
public class CustomComparer : IComparer
#region IComparer Members
public int Compare(object x, object y)
GridStyleInfoStore style1 = x as GridStyleInfoStore;
GridStyleInfoStore style2 = y as GridStyleInfoStore;
object val1 = null;
object val2 = null;
if (style1 != null)
val1 = style1.GetValue(GridStyleInfoStore.CellValueProperty);
if (style2 != null)
val2 = style2.GetValue(GridStyleInfoStore.CellValueProperty);
if (val1 == null && val2 == null)
else if (val1 == null)
else if (val2 == null)
// You could now implement here your own custom compare technique ...
if (val1 is IComparable && val2 is IComparable)
int r = ((IComparable) val1).CompareTo(val2);
catch (Exception ex)
Instead of casting the .CellValue to Cint when you assign it you could then instead do the casting in the Comparer.
We'll also look what would need to be changed if we want to take care of such sorting automatically but for now I would recommend such a custom comparer.
AdministratorOctober 20, 2003 05:20 PM UTC
I forgot to mention. Please open a support incident and we can send download instructions for this patch.