DataGridView.EditingControlShowing Event

 

Occurs when a control for editing a cell is showing.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public event DataGridViewEditingControlShowingEventHandler EditingControlShowing

You can handle this event to perform custom initialization of the editing control when a cell enters edit mode. To customize the display characteristics of the control, set the properties of the object returned by the DataGridViewEditingControlShowingEventArgs.CellStyle property. To perform other initialization, cast the value of the DataGridViewEditingControlShowingEventArgs.Control property to the specific control type and access the members directly. For example, you can handle the EditingControlShowing event to attach event-handlers to the events of the editing control.

System_CAPS_noteNote

The DataGridView control hosts one editing control at a time, and reuses the editing control whenever the cell type does not change between edits. When attaching event-handlers to the editing control, you must therefore take precautions to avoid attaching the same handler multiple times. To avoid this problem, remove the handler from the event before you attach the handler to the event. This will prevent duplication if the handler is already attached to the event, but will have no effect otherwise. For more information, see the example code in the DataGridViewComboBoxEditingControl class overview.

For more information about handling events, see NIB: Consuming Events.

The following code example illustrates how to handle this event to change the BackColor property of the current cell. To run this example, paste the code into a form that contains a DataGridView named dataGridView1 and ensure that the EditingControlShowing event is associated with the event handler.

private void dataGridView1_EditingControlShowing(object sender, 
    DataGridViewEditingControlShowingEventArgs e)
{
    e.CellStyle.BackColor = Color.Aquamarine;
}

.NET Framework
Available since 2.0
Return to top
Show: