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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CellValueType and sorting

Thread ID:





8089 Oct 20,2003 04:13 PM UTC Oct 20,2003 05:20 PM UTC WinForms 2
Tags: GridControl
Justin Holman
Asked On October 20, 2003 04:13 PM UTC

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. Thank you

Administrator [Syncfusion]
Replied On October 20, 2003 05:11 PM UTC

In the 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) 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 } 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. Stefan

Administrator [Syncfusion]
Replied On October 20, 2003 05:20 PM UTC

I forgot to mention. Please open a support incident and we can send download instructions for this patch. 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