DataGridView.EditingControl 属性

定义

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

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control EditingControl { get; }
C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control? EditingControl { get; }

属性值

当前单元格承载的 Control

属性

示例

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

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

C#
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;
    }
}

注解

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

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅