The Syncfusion® native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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
SHStefan 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