DataGridView.EditingControlShowing 事件

定义

显示用于编辑单元格的控件时发生。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 

示例

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

备注

@No__t-0 控件一次承载一个编辑控件,并且每当该单元格类型在编辑之间没有更改时,重复使用编辑控件。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.

适用于

另请参阅