Version

ColumnSorting Event

The ColumnSorting event is raised when the user changes the sort on the XamGrid via the GUI.
Syntax
'Declaration
 
Public Event ColumnSorting As EventHandler(Of SortingCancellableEventArgs)
public event EventHandler<SortingCancellableEventArgs> ColumnSorting
Event Data

The event handler receives an argument of type SortingCancellableEventArgs containing data related to this event. The following SortingCancellableEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from Infragistics.CancellableEventArgs) 
Column (Inherited from Infragistics.Controls.Grids.CancellableColumnEventArgs)The CancellableColumnEventArgs.Column that this event was triggered for.
NewSortDirection Gets the SortDirection as it will be applied.
PreviousSortDirection Gets the SortDirection prior to the change being made.
Example
This sample demonstrates how to handle the ColumnSorting event which is fired the moment right before a column is sorted.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Private Sub MyGrid_ColumnSorting(ByVal sender As System.Object, ByVal e As SortingCancellableEventArgs)

'If the column is fixed to the left, do not allow that column to be sorted
   If e.Column.IsFixed = FixedState.Left Then
      System.Diagnostics.Debug.WriteLine("Cannot sort on fixed columns")
      e.Cancel = True
      Return
   End If

   System.Diagnostics.Debug.WriteLine(e.Column.Key + " Column sorted from " +   e.PreviousSortDirection.ToString() + " to " + e.NewSortDirection.ToString())
End Sub
private void MyGrid_ColumnSorting(object sender, SortingCancellableEventArgs e)
{
   // If the column is fixed to the left, do not allow that column to be 
   // sorted
   if (e.Column.IsFixed == FixedState.Left)
   {
      System.Diagnostics.Debug.WriteLine("Cannot sort on fixed columns");
      e.Cancel = true;
      return;
   }

     System.Diagnostics.Debug.WriteLine(e.Column.Key+" Column sorted from: " +  
      e.PreviousSortDirection + "\n to: " + e.NewSortDirection);
}
<ig:XamGrid x:Name="MyGrid"         
    
ColumnSorting="MyGrid_ColumnSorting">
</ig:XamGrid>
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also