Export (0) Print
Expand All
Expand Minimize

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.

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 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

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft