DataGridView.EditingControlShowing DataGridView.EditingControlShowing DataGridView.EditingControlShowing DataGridView.EditingControlShowing Event

定义

显示用于编辑单元格的控件时发生。Occurs when a control for editing a cell is showing.

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 

示例

下面的代码示例演示了如何处理此事件以更改BackColor当前单元格的属性。The following code example illustrates how to handle this event to change the BackColor property of the current cell. 若要运行此示例,请将代码粘贴到包含一个窗体DataGridView名为dataGridView1并确保EditingControlShowing事件是与事件处理程序相关联。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

注解

可以处理此事件时要执行的编辑控件的自定义初始化的单元格进入编辑模式。You can handle this event to perform custom initialization of the editing control when a cell enters edit mode. 若要自定义控件的显示特性,请设置返回的对象的属性DataGridViewEditingControlShowingEventArgs.CellStyle属性。To customize the display characteristics of the control, set the properties of the object returned by the DataGridViewEditingControlShowingEventArgs.CellStyle property. 若要执行其他初始化,将值强制转换的DataGridViewEditingControlShowingEventArgs.Control属性特定于控件类型和直接访问的成员。To perform other initialization, cast the value of the DataGridViewEditingControlShowingEventArgs.Control property to the specific control type and access the members directly. 例如,可以处理EditingControlShowing事件以将事件处理程序附加到编辑控件的事件。For example, you can handle the EditingControlShowing event to attach event-handlers to the events of the editing control.

备注

DataGridView控制一次承载一个编辑控件和单元格类型之间的编辑不发生更改时重新使用编辑控件。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. 有关详细信息,请参阅中的示例代码DataGridViewComboBoxEditingControl类概述。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.

适用于

另请参阅