Xceed Grid for WinForms v4.3 Documentation
Using the EnteringEdit event

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Events > Using the EnteringEdit event

The EnteringEdit event is raised before editing a cell. It provides the possibility to prevent the cell from being edited and to change the CellEditorManager that will be used to edit the cell.

Basic steps - C#

To subscribe to the EnteringEdit event, the following steps must be performed:

  • Obtain a reference to a Cell object. 

  • Subscribe to the EnteringEdit event of the Cell object using the EnteringEditEventHandler delegate class 

  • Create a new method that will handle the events that are raised. 

  • Place the desired code in the newly created event handler.

Basic steps - VB.NET

To subscribe to the EnteringEdit event, the following steps must be performed:

Demonstration

This example assumes that you are in a Windows application.

VB.NET
Copy Code
Imports Xceed.Grid
Dim cell As Cell
For Each cell in gridControl1.DataRowTempate.Cells
  AddHandler cell.EnteringEdit, AddressOf Me.cell_EnteringEdit
Next cell
Private Sub cell_EnteringEdit( ByVal sender As Object, ByVal e As EnteringEditEventArgs )
  Try
    If sender.ParentColumn.DataType = TypeOf( String ) Then
      e.CellEditorManager = New Xceed.Grid.Editors.TextEditor()
    End If
  Catch exception As Exception
    MessageBox.Show( exception.ToString() )
  End Try
End Sub
' If you no longer wish to handle the EnteringEdit events that are raised,
' you can unsubscribe from the event notification by doing the following:
RemoveHandler cell.EnteringEdit, AddressOf Me.cell_EnteringEdit
C#
Copy Code
using Xceed.Grid;
foreach( Cell cell in gridControl1.DataRowTemplate.Cells )
{
  cell.EnteringEdit += new EnteringEditEventHandler( this.cell_EnteringEdit );
}
// This method will handle the EnteringEdit events that are raised.
private void cell_EnteringEdit( object sender, EnteringEditEventArgs e )
{
  try
  {
    if( ( ( Cell )sender ).ParentColumn.DataType == typeof( string ) )
    {
      e.CellEditorManager = new Xceed.Grid.Editors.TextEditor();
    }
  }
  catch( Exception exception )
  {
    MessageBox.Show( exception.ToString() );
  }
}
// If you no longer wish to handle the EnteringEdit events that are raised,
// you can unsubscribe from the event notification by doing the following:
cell.EnteringEdit -= new EnteringEditEventHandler( this.cell_EnteringEdit );