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

Databound Grid Column Sorting

Is there a way to determine which column is currently sorted and if it is sorted ascending/descending? I have a databound grid that is refreshed based on other form events. Each time the grids datasourece is updated I am calling the ColumnSort(1) to ensure that the grid is sorted. This is causing the grid to toggle between an ascending and descending sort, even though the data has been refreshed. I thought about checking to see if it is currently sorted and then only sorting if needed, but I could not find a way to determine if it was sorted. Should the sort be maintained, even though the datasource has changed? Thanks - Anthony

1 Reply

SH Stefan Hoenig Syncfusion Team November 4, 2002 05:41 PM UTC

Hi Anthony, the following methods should let you do all the sorting directly on the underlying datasource: public static ListSortDirection GetSortDirection(IList list) { if (list is IBindingList && ((IBindingList)list).SupportsSorting) return ((IBindingList)list).SortDirection; return ListSortDirection.Ascending; } public static PropertyDescriptor GetSortProperty(IList list) { if (list is IBindingList && ((IBindingList)list).SupportsSorting) return ((IBindingList)list).SortProperty; return null; } public static void SetSort(IList list, PropertyDescriptor property, ListSortDirection sortDirection) { if (list is IBindingList && ((IBindingList)list).SupportsSorting) ((IBindingList)list).ApplySort(property, sortDirection); } public static bool SupportsSort(IList list) { return list is IBindingList && ((IBindingList)list).SupportsSorting; } I'll make a note that the Sort method in the GridModelDataBinder should accept a SortDirection. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon