Version

BeforeExitEditMode Event (UltraGrid)

Occurs before a cell exits edit mode.
Syntax
'Declaration
 
Public Event BeforeExitEditMode As BeforeExitEditModeEventHandler
public event BeforeExitEditModeEventHandler BeforeExitEditMode
Event Data

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

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
CancellingEditOperation Indicates whether the edit operation is being canceled.
ForceExit Indicates whether cell is being forced to exit the edit mode.
Remarks

The cancel argument enables you to programmatically prevent the cell from exiting edit mode. This argument can be used to prevent the cell from leaving edit mode unless a certain condition is met.

When a cell is not in edit mode, the control's IsInEditMode property is set to False.

The AfterExitEditMode event, which occurs after a cell exits edit mode, is generated after this event, provided cancel is not set to True.

The BeforeEnterEditMode event is generated before a cell enters edit mode.

Example
Following code shows how one can use BeforeExitEditMode event to perform input validation.

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_BeforeExitEditMode(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs) Handles ultraGrid1.BeforeExitEditMode

      ' If the user is canceling the modifications (for example by hitting Escape 
      ' key, then just return because the cell will revert to its original value
      ' in this case and not commit the user's input.
      If e.CancellingEditOperation Then Return

      ' See if the cell in edit mode is from CustomerID column.
      If Me.ultraGrid1.ActiveCell.Column.Key = "CustomerID" Then
          If Me.ultraGrid1.ActiveCell.Text.Length < 4 Then
              ' If the length of the input text is less than 4, then show a message
              ' box to the user.
              MessageBox.Show("Customer ID must be at least 4 characters wide.", _
                              "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

              ' If ForceExit is true, then the UltraGrid will exit the edit mode
              ' regardless of whether you cancel this event or not. ForceExit would
              ' be true for example when the UltraGrid is being disposed of and thus
              ' it can't stay in edit mode. In which case setting Cancel won't do
              ' any good so just cancel the update to revert the cell's value back
              ' to its original value.
              If e.ForceExit Then
                  ' If the UltraGrid must exit the edit mode, then cancel the
                  ' cell update so the original value gets restored in the cell.
                  Me.ultraGrid1.ActiveCell.CancelUpdate()
                  Return
              End If

              ' In normal circumstances where ForceExit is false, set Cancel to 
              ' true so the UltraGrid doesn't exit the edit mode.
              e.Cancel = True
          End If
      End If

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

private void ultraGrid1_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e)
{

	// If the user is canceling the modifications (for example by hitting Escape 
	// key, then just return because the cell will revert to its original value
	// in this case and not commit the user's input.
	if ( e.CancellingEditOperation )
		return;

	// See if the cell in edit mode is from CustomerID column.
	if ( this.ultraGrid1.ActiveCell.Column.Key == "CustomerID" )
	{
		if ( this.ultraGrid1.ActiveCell.Text.Length < 4 )
		{
			// If the length of the input text is less than 4, then show a message
			// box to the user.
			MessageBox.Show( 
				"Customer ID must be at least 4 characters wide.", 
				"Input Error",
				MessageBoxButtons.OK,
				MessageBoxIcon.Error );

			// If ForceExit is true, then the UltraGrid will exit the edit mode
			// regardless of whether you cancel this event or not. ForceExit would
			// be true for example when the UltraGrid is being disposed of and thus
			// it can't stay in edit mode. In which case setting Cancel won't do
			// any good so just cancel the update to revert the cell's value back
			// to its original value.
			if ( e.ForceExit )
			{
				// If the UltraGrid must exit the edit mode, then cancel the
				// cell update so the original value gets restored in the cell.
				this.ultraGrid1.ActiveCell.CancelUpdate( );
				return;
			}

			// In normal circumstances where ForceExit is false, set Cancel to 
			// true so the UltraGrid doesn't exit the edit mode.
			e.Cancel = true;
		}
	}

}
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