DataGridView.EditingControl 属性

定义

获取当前单元格承载的控件(如果包含编辑控件的单元格处于编辑模式下)。

public:
 property System::Windows::Forms::Control ^ EditingControl { System::Windows::Forms::Control ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control EditingControl { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control? EditingControl { get; }
[<System.ComponentModel.Browsable(false)>]
member this.EditingControl : System.Windows.Forms.Control
Public ReadOnly Property EditingControl As Control

属性值

当前单元格承载的 Control

属性

示例

下面的代码示例演示如何在自定义单元格类型的重写方法中使用此属性。 在该示例中,检索对编辑控件的引用,转换为自定义编辑控件类型,然后使用单元格的当前值进行填充。

本示例是How to: Host Controls in Windows 窗体 DataGridView Cells中提供的更大示例的一部分。

public override void InitializeEditingControl(int rowIndex, object 
    initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
    // Set the value of the editing control to the current cell value.
    base.InitializeEditingControl(rowIndex, initialFormattedValue, 
        dataGridViewCellStyle);
    CalendarEditingControl ctl = 
        DataGridView.EditingControl as CalendarEditingControl;
    // Use the default row value when Value property is null.
    if (this.Value == null)
    {
        ctl.Value = (DateTime)this.DefaultNewRowValue;
    }
    else
    {
        ctl.Value = (DateTime)this.Value;
    }
}
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
    ByVal initialFormattedValue As Object, _
    ByVal dataGridViewCellStyle As DataGridViewCellStyle)

    ' Set the value of the editing control to the current cell value.
    MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
        dataGridViewCellStyle)

    Dim ctl As CalendarEditingControl = _
        CType(DataGridView.EditingControl, CalendarEditingControl)

    ' Use the default row value when Value property is null.
    If (Me.Value Is Nothing) Then
        ctl.Value = CType(Me.DefaultNewRowValue, DateTime)
    Else
        ctl.Value = CType(Me.Value, DateTime)
    End If
End Sub

注解

如果单元格未处于编辑模式或单元格类型不适合编辑控件,则此属性返回 null

适用于

另请参阅