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. Image for the cookie policy date

sorting integers in columns typeof(System.String)

Hi, one of my datatable contains a column typeof(string). these column contains text and numbers and is connected as a gridboundcolumn in the databoundgrid. when i sort (by dblclick col-header), the result is: 1 10 11 2 20 abc --------------------------------------- but i need the result: 1 2 10 11 20 abc --------------------------------------- in integer columns it works fine. to set the styleinfo for the column was not succesfuly. gbc.StyleInfo.CellValueType = typeof(Int64); is there a way to sort string-colums like integer-columns? greeting markus p.s. the sort sample has the same behavor when sorted mixed content in string-columns.

1 Reply

AD Administrator Syncfusion Team October 1, 2003 08:58 AM

Right now there is no easy way. But, I'll add some method overloads to GridData that will let you pass in a custom comparer for the styles/values. 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) return 0; else if (val1 == null) return -1; else if (val2 == null) return 1; else { try { // You could now implement here your own custom compare technique ... if (val1 is IComparable && val2 is IComparable) { int r = ((IComparable) val1).CompareTo(val2); return r; } } catch (Exception ex) { } return val1.ToString().CompareTo(val2.ToString()); } } #endregion } Change will be in the next builds 1.6.1.8 and/or 2.0.0.x next time we release a new build. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon