Version

BeforeSortChange Event

Occurs before the sort indicator is changed.
Syntax
'Declaration
 
Public Event BeforeSortChange As BeforeSortChangeEventHandler
public event BeforeSortChangeEventHandler BeforeSortChange
Event Data

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

PropertyDescription
Band The band (read-only)
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
ProcessMode The process mode for the sort
SortedColumns The sorted columns (read-only)
Remarks

The band argument returns a reference to an UltraGridBand object that can be used to set properties of, and invoke methods on, the band that will be sorted. You can use this reference to access any of the returned band's properties or methods.

The UltraGrid can automatically sort the contents of columns without the addition of any code, provided the control is able to preload the rows in the band. Preloading is enabled by default if the recordset bound to the band contains less than 1000 rows. If you do not want to preload rows, but you still want to provide column sorting in the control, you must implement column sorting yourself using the BeforeSortChange and AfterSortChange events.

The SortedColumns collection can be used to retrieve reference to the cloned UltraGridColumn objects being sorted. You can use this reference to access any of the returned collection's properties or methods, as well as the properties or methods of the objects within the collection.

The cancel argument enables you to programmatically prevent the columns from being sorted. This argument can be used to prevent the user from sorting columns unless a certain condition is met.

The AfterSortChange event, which occurs after a sort action is completed, is generated after this event, provided cancel is not set to True.

Example
The following code illustrates some of the information available in the BeforeSortChange event and its potential uses.

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.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private Sub UltraGrid1_BeforeSortChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeSortChangeEventArgs) Handles ultraGrid1.BeforeSortChange

      ' The BeforeSortChange event fires when the user sorts rows by a column
      ' or groups rows by a column. So you can use BeforeSortChange event to control
      ' how the user sort rows as well as groups rows. The SortedColumns parameter off 
      ' the passed in event args contains all the group-by columns and sort 
      ' columns (in that order).

      Dim i As Integer
      Dim numberOfGroupByColumns As Integer = 0

      ' TIP: Group-by columns are always before any non-group-by columns in the
      ' SortedColumnsCollection. (Even if the group-by columns were added
      ' after adding non-group-by columns).

      ' Find out the number of group by columns by traversing the sorted columns
      ' collection.
      For i = 0 To e.SortedColumns.Count - 1
          If (e.SortedColumns(i).IsGroupByColumn) Then
              numberOfGroupByColumns += 1
          Else
              Exit For
          End If
      Next

      ' You can cancel the event so the grid won't proceed with the changes.
      If numberOfGroupByColumns > 2 Then
          ' Enforce the user to have no more than 2 group-by columns.
          e.Cancel = True
          Return
      End If

	' The ProcessMode property of the BeforeSortChangeEventArgs event argument provides the ability
	' to specify whether sorting and filtering of rows will occur synchronously or lazily.
	' This can be usefull in situations where the grid contains a large number of records
	' and the developer wishes to display a wait cursor during the sort.  By default the grid applies
	' sorting and filtering lazily to rows in each band as it is expanded.  If the ProccessMode property
	' is set to either Synchronous or SynchronousExpanded the developer can ensure that either all rows
	' in all bands, or all expanded rows in all bands are synchronously sorted and filtered, i.e., all at once.
	' If a more fine grained approach is desired the RowsCollection overloaded EnsureSortedAndFiltered method
	' can be used to specify how far down in the hierarchy of bands synchronous sorting and filtering should be applied.

	' Setting the ProcessMode to Lazy specifies that the grid should apply sorting and filtering lazily
	' to rows in each band as it is expanded.  This is the default behavior of the grid.
	e.ProcessMode = ProcessMode.Lazy

	' Setting the ProcessMode to Synchronous specifies that the grid should apply sorting and filtering
	' synchronously to all rows in all bands.
	e.ProcessMode = ProcessMode.Synchronous

	' Setting the ProcessMode to SynchronousExpanded specifies that the grid should apply sorting and filtering
	' synchronously to all expanded rows in all bands.
	e.ProcessMode = ProcessMode.SynchronousExpanded

	' This code specifies that a wait cursor should be displayed during a sort and ensures that all rows in all
	' bands are sorted while the wait cursor is displayed.  The cursor should be reset in the grid's AfterSortChange
	' event.
	e.ProcessMode = ProcessMode.Synchronous
	Me.ultraGrid1.Cursor = Cursors.WaitCursor

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void ultraGrid1_BeforeSortChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSortChangeEventArgs e)
{

	// The BeforeSortChange event fires when the user sorts rows by a column
	// or groups rows by a column. So you can use BeforeSortChange event to control
	// how the user sort rows as well as groups rows. The SortedColumns parameter off 
	// the passed in event args contains all the group-by columns and sort 
	// columns (in that order).
	
	int i;
	int numberOfGroupByColumns = 0;

	// TIP: Group-by columns are always before any non-group-by columns in the
	// SortedColumnsCollection. (Even if the group-by columns were added
	// after adding non-group-by columns).

	// Find out the number of group by columns by traversing the sorted columns
	// collection.
	for ( i = 0; i < e.SortedColumns.Count; i++ )
	{
		if ( e.SortedColumns[ i ].IsGroupByColumn )
			numberOfGroupByColumns++;
		else 
			break;
	}

	// You can cancel the event so the grid won't proceed with the changes.
	if ( numberOfGroupByColumns > 2 )
	{
		// Enfore the user only have no more than 2 group-by columns.
		e.Cancel = true;
		return;
	}

	// The ProcessMode property of the BeforeSortChangeEventArgs event argument provides the ability
	// to specify whether sorting and filtering of rows will occur synchronously or lazily.
	// This can be usefull in situations where the grid contains a large number of records
	// and the developer wishes to display a wait cursor during the sort.  By default the grid applies
	// sorting and filtering lazily to rows in each band as it is expanded.  If the ProccessMode property
	// is set to either Synchronous or SynchronousExpanded the developer can ensure that either all rows
	// in all bands, or all expanded rows in all bands are synchronously sorted and filtered, i.e., all at once.
	// If a more fine grained approach is desired the RowsCollection overloaded EnsureSortedAndFiltered method can be used
	// to specify how far down in the hierarchy of bands synchronous sorting and filtering should be applied.

	// Setting the ProcessMode to Lazy specifies that the grid should apply sorting and filtering lazily
	// to rows in each band as it is expanded.  This is the default behavior of the grid.
	e.ProcessMode = ProcessMode.Lazy;

	// Setting the ProcessMode to Synchronous specifies that the grid should apply sorting and filtering
	// synchronously to all rows in all bands.
	e.ProcessMode = ProcessMode.Synchronous;

	// Setting the ProcessMode to SynchronousExpanded specifies that the grid should apply sorting and filtering
	// synchronously to all expanded rows in all bands.
	e.ProcessMode = ProcessMode.SynchronousExpanded;

	// This code specifies that a wait cursor should be displayed during a sort and ensures that all rows in all
	// bands are sorted while the wait cursor is displayed.  The cursor should be reset in the grid's AfterSortChange
	// event.
	e.ProcessMode = ProcessMode.Synchronous;
	this.ultraGrid1.Cursor = Cursors.WaitCursor;

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, 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