共用方式為


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 Forms 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 回 。

適用於

另請參閱