Hi,
I am unable to find OldSortingState & NewSortingState properties in GridViewSortingEventArgs.. Follwing is your example, Please suggest
private void CustomSortingGrid_Sorting( object sender, GridViewSortingEventArgs e )
{
//Gets the value of the ItemsSource property as IEnumerable.
IEnumerable<Employee> employees = e.DataControl.ItemsSource as IEnumerable<Employee>;
//Checks if the value of the collection is null.
if ( employees == null )
{
e.Cancel = true;
return;
}
//If the sorting state is none, sort the items ascending.
if ( e.OldSortingState == SortingState.None )
{
e.NewSortingState = SortingState.Ascending;
employees = employees.OrderBy( employee => employee.GetType()
.GetProperty( e.SortPropertyName )
.GetValue( employee, null ) );
}
//If the sorting state is none, sort the items descending.
else if ( e.OldSortingState == SortingState.Ascending )
{
e.NewSortingState = SortingState.Descending;
employees = employees.OrderByDescending( employee => employee.GetType()
.GetProperty( e.SortPropertyName )
.GetValue( employee, null ) );
}
//If the sorting state is descending, apply default sorting to the items.
else
{
e.NewSortingState = SortingState.None;
employees = employees.OrderBy( employee => employee.EmployeeID );
}
//Set the sorted collection as source of the RadGridView
e.DataControl.ItemsSource = employees.ToList();
e.Cancel = true;
}
I am unable to find OldSortingState & NewSortingState properties in GridViewSortingEventArgs.. Follwing is your example, Please suggest
private void CustomSortingGrid_Sorting( object sender, GridViewSortingEventArgs e )
{
//Gets the value of the ItemsSource property as IEnumerable.
IEnumerable<Employee> employees = e.DataControl.ItemsSource as IEnumerable<Employee>;
//Checks if the value of the collection is null.
if ( employees == null )
{
e.Cancel = true;
return;
}
//If the sorting state is none, sort the items ascending.
if ( e.OldSortingState == SortingState.None )
{
e.NewSortingState = SortingState.Ascending;
employees = employees.OrderBy( employee => employee.GetType()
.GetProperty( e.SortPropertyName )
.GetValue( employee, null ) );
}
//If the sorting state is none, sort the items descending.
else if ( e.OldSortingState == SortingState.Ascending )
{
e.NewSortingState = SortingState.Descending;
employees = employees.OrderByDescending( employee => employee.GetType()
.GetProperty( e.SortPropertyName )
.GetValue( employee, null ) );
}
//If the sorting state is descending, apply default sorting to the items.
else
{
e.NewSortingState = SortingState.None;
employees = employees.OrderBy( employee => employee.EmployeeID );
}
//Set the sorted collection as source of the RadGridView
e.DataControl.ItemsSource = employees.ToList();
e.Cancel = true;
}