DataGridView.EditingControl Property

Definition

Gets the control hosted by the current cell, if a cell with an editing control is in edit mode.

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

Property Value

The Control hosted by the current cell.

Attributes

Examples

The following code example illustrates how to use this property in an overridden method of a custom cell type. In the example, a reference to the editing control is retrieved, cast to a custom editing control type, and then populated with the current value of the cell.

This example is part of a larger example available in How to: Host Controls in Windows Forms 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;
    }
}

Remarks

If the cell is not in edit mode or the cell type does not accommodate an editing control, this property returns null.

Applies to

Product Versions
.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

See also