Uredi

Deli z drugimi prek


DataGridView.EditingControlShowing Event

Definition

Occurs when a control for editing a cell is showing.

public:
 event System::Windows::Forms::DataGridViewEditingControlShowingEventHandler ^ EditingControlShowing;
public event System.Windows.Forms.DataGridViewEditingControlShowingEventHandler EditingControlShowing;
public event System.Windows.Forms.DataGridViewEditingControlShowingEventHandler? EditingControlShowing;
member this.EditingControlShowing : System.Windows.Forms.DataGridViewEditingControlShowingEventHandler 
Public Custom Event EditingControlShowing As DataGridViewEditingControlShowingEventHandler 

Event Type

Examples

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;
}
Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _
    ByVal e As DataGridViewEditingControlShowingEventArgs) _
    Handles dataGridView1.EditingControlShowing

    e.CellStyle.BackColor = Color.Aquamarine

End Sub

Remarks

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.

Note

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 how to handle events, see Handling and Raising Events.

Applies to

See also