Version

BeforeGroupPosChanged Event

Occurs before one or more groups have been moved, swapped, or sized.
Syntax
'Declaration
 
Public Event BeforeGroupPosChanged As BeforeGroupPosChangedEventHandler
public event BeforeGroupPosChangedEventHandler BeforeGroupPosChanged
Event Data

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

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
GroupHeaders groups (read-only)
GroupPosChangedType group position changed type (read-only)
Remarks

The action argument indicates which action will occur to the group or groups: moving, swapping, or sizing.

The groups argument returns a reference to a Groups collection that can be used to retrieve references to the UltraGridGroup object or objects that will be moved, swapped, or sized. 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. However, all properties of the affected groups are read-only in this event procedure.

The cancel argument enables you to programmatically prevent the group or groups from being moved, swapped, or sized. This argument can be used to prevent the user from moving, swapping, or sizing groups unless a certain condition is met. To prevent the user from attempting to move or swap a group, set the AllowGroupMoving or AllowGroupSwapping properties, respectively.

This event is generated before one or more groups are moved, swapped, or sized, either programmatically, or by user interaction. A group can be sized programmatically by setting its Width property and can be moved programmatically by setting its header's VisiblePosition property.

The VisiblePosition property can be used to determine both the current and new positions of the group or groups that will be moved or swapped. New positions can be determined by reading the property off of the header of the group or groups in groups, while current positions can be determined by reading the property off of the header of the group or group in the appropriate band.

The BeforeColPosChanged event is generated before one or more columns are moved, swapped, or sized.

The AfterGroupPosChanged event, which occurs after one or more groups are moved, swapped, or sized, is generated after this event, provided cancel is not set to True.

Example
Following code illustrates some of the information available in BeforeGroupPosChanged event and potential uses of the event.

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_BeforeGroupPosChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeGroupPosChangedEventArgs) Handles ultraGrid1.BeforeGroupPosChanged
      ' BeforeGroupPosChanged gets fired when the user moves, swaps or resizes a group
      ' or groups. This event gives a chance to cancel the user action.

      If PosChanged.Moved = e.PosChanged Then
          ' One or more groups are being moved

          Dim groupList As String = ""

          Dim i As Integer
          For i = 0 To e.GroupHeaders.Length - 1
              If i > 0 Then groupList = groupList & ", "
              groupList = groupList + e.GroupHeaders(i).Caption
          Next

          Dim result As DialogResult = MessageBox.Show( _
              "You are about to move " & groupList & " groups. Do you want to continue ?", _
              "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

          If DialogResult.No = result Then
              ' Cancel the move by setting Cancel off the event args.
              e.Cancel = True
          End If
      ElseIf PosChanged.Swapped = e.PosChanged Then
          ' Two groups are being swapped.

          Dim result As DialogResult = MessageBox.Show( _
                  "You are about to swap " & e.GroupHeaders(0).Caption & " with " _
                  & e.GroupHeaders(1).Caption & " Do you want to continue ?", _
                  "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

          If DialogResult.No = result Then
              ' Cancel the move by setting Cancel off the event args.
              e.Cancel = True
          End If
      ElseIf PosChanged.Sized = e.PosChanged Then
          ' A group is bieng resized.

          ' When a group is being resized, e.GroupHeaders contains the group header that's
          ' being resized.
          Debug.WriteLine("User is about to resize " & e.GroupHeaders(0).Caption & " group.")
      End If
  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void ultraGrid1_BeforeGroupPosChanged(object sender, Infragistics.Win.UltraWinGrid.BeforeGroupPosChangedEventArgs e)
{
	// BeforeGroupPosChanged gets fired when the user moves, swaps or resizes a group
	// or groups. This event gives a chance to cancel the user action.

	if ( PosChanged.Moved == e.PosChanged )
	{
		// One or more groups are being moved

		string groupList = "";
		
		for ( int i = 0; i < e.GroupHeaders.Length; i++ )
		{
			if ( i > 0 )
				groupList = groupList + ", ";

			groupList = groupList + e.GroupHeaders[i].Caption;
		}

		DialogResult result = MessageBox.Show( 
			"You are about to move " + groupList + " groups. Do you want to continue ?",
			"Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question );

		if ( DialogResult.No == result )
		{
			// Cancel the move by setting Cancel off the event args.
			e.Cancel = true;
		}
	}
	else if ( PosChanged.Swapped == e.PosChanged )
	{
		// Two groups are being swapped.

		DialogResult result = MessageBox.Show( 
			"You are about to swap " + e.GroupHeaders[0].Caption + " with " 
			+ e.GroupHeaders[1].Caption + " Do you want to continue ?", 
			"Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question );

		if ( DialogResult.No == result )
		{
			// Cancel the move by setting Cancel off the event args.
			e.Cancel = true;
		}
	}
	else if ( PosChanged.Sized == e.PosChanged )
	{
		// A group is bieng resized.

		// When a group is being resized, e.GroupHeaders contains the group header that's
		// being resized.
		Debug.WriteLine( "User is about to resize " + e.GroupHeaders[0].Caption + " group." );
	}
}
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