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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

sorting integers in columns typeof(System.String)

Thread ID:





7562 Oct 1,2003 11:27 AM UTC Oct 1,2003 12:58 PM UTC WinForms 1
Tags: GridControl
Markus Kraft
Asked On October 1, 2003 11:27 AM UTC

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.

Administrator [Syncfusion]
Replied On October 1, 2003 12:58 PM UTC

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 and/or 2.0.0.x next time we release a new build. Stefan


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon