Version

BeforeEnterEditMode Event (UltraGrid)

Occurs before a cell enters edit mode.
Syntax
'Declaration
 
Public Event BeforeEnterEditMode As CancelEventHandler
public event CancelEventHandler BeforeEnterEditMode
Event Data

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

PropertyDescription
Cancel  
Remarks

Thecancelargument enables you to programmatically prevent the cell from entering edit mode, meaning that the cell is prepared to accept input from the user. This argument can be used to prevent the cell from entering edit mode unless a certain condition is met.

This event is generated before a cell enters edit mode. This is different from cell activation, which occurs when the cell receives focus. TheBeforeCellActivateevent is generated before a cell is activated.

When a cell is in edit mode, the control'sIsInEditModeproperty is set to True.

TheAfterEnterEditModeevent, which occurs after a cell enters edit mode, is generated after this event, providedcancelis not set to True.

TheBeforeExitEditModeevent is generated before a cell exits edit mode.

Example
Following code makes use of BeforeEnterEditMode and AfterExitEditMode events to mark the cells that have been modified by the user with red forecolor.

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 origCellVal As Object = Nothing

  Private Sub UltraGrid1_BeforeEnterEditMode(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ultraGrid1.BeforeEnterEditMode

      ' BeforeEnterEditMode gets fired before a cell goes into the edit mode.
      ' ActiveCell property off the UltraGrid tells which cell is about to 
      ' go into the edit mode.

      ' Before entering the edit mode, store the original value of the cell 
      ' so we can compare it later in AfterExitEditMode to see if it's changed.
      Me.origCellVal = Me.ultraGrid1.ActiveCell.Value

  End Sub

  Private Sub UltraGrid1_AfterExitEditMode(ByVal sender As Object, ByVal e As System.EventArgs) Handles ultraGrid1.AfterExitEditMode

      ' AfterExitEditMode gets fired after a cell exits the edit mode.
      ' ActiveCell property off the UltraGrid can be used to get the cell
      ' that has just exitted the edit mode.

      ' Get the new cell value nad compare it with the original to see
      ' if the user has modified the value.
      Dim cellModified As Boolean = False

      ' Get the new value of the cell that has just exited the edit mode.
      Dim newCellVal As Object = Me.ultraGrid1.ActiveCell.Value

      ' Compare the new value to the original cell value that we stored in
      ' BeforeEnterEditMode.
      If (Not newCellVal Is Me.origCellVal And Not Nothing Is Me.origCellVal And _
          Not Nothing Is newCellVal) AndAlso Not Me.origCellVal.Equals(newCellVal) Then
          cellModified = True
      End If

      If cellModified Then
          ' If the user modified the cell's value, set the BackColor of
          ' the cell's appearance to Gray.
          Me.ultraGrid1.ActiveCell.Appearance.ForeColor = Color.Red
      End If

      ' Reset the origCellVal to nothing
      Me.origCellVal = Nothing

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

   private object origCellVal = null;

private void ultraGrid1_BeforeEnterEditMode(object sender, System.ComponentModel.CancelEventArgs e)
{

	// BeforeEnterEditMode gets fired before a cell goes into the edit mode.
	// ActiveCell property off the UltraGrid tells which cell is about to 
	// go into the edit mode.

	// Before entering the edit mode, store the original value of the cell 
	// so we can compare it later in AfterExitEditMode to see if it's changed.
	this.origCellVal = this.ultraGrid1.ActiveCell.Value;

}

private void ultraGrid1_AfterExitEditMode(object sender, System.EventArgs e)
{

	// AfterExitEditMode gets fired after a cell exits the edit mode.
	// ActiveCell property off the UltraGrid can be used to get the cell
	// that has just exitted the edit mode.

	// Get the new cell value nad compare it with the original to see
	// if the user has modified the value.
	bool cellModified = false;

	// Get the new value of the cell that has just exited the edit mode.
	object newCellVal = this.ultraGrid1.ActiveCell.Value;

	// Compare the new value to the original cell value that we stored in
	// BeforeEnterEditMode.
	if ( newCellVal != this.origCellVal &&
		 null != this.origCellVal && null != newCellVal &&
		 !this.origCellVal.Equals( newCellVal ) )
	{
		cellModified = true;
	}

	if ( cellModified )
	{
		// If the user modified the cell's value, set the BackColor of
		// the cell's appearance to Gray.
		this.ultraGrid1.ActiveCell.Appearance.ForeColor = Color.Red;
	}
	
	// Reset the origCellVal to null
	this.origCellVal = null;

}
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