共用方式為


DataGridView.CellBeginEdit 事件

定義

啟動所選取儲存格的編輯模式時發生。

public:
 event System::Windows::Forms::DataGridViewCellCancelEventHandler ^ CellBeginEdit;
public event System.Windows.Forms.DataGridViewCellCancelEventHandler CellBeginEdit;
public event System.Windows.Forms.DataGridViewCellCancelEventHandler? CellBeginEdit;
member this.CellBeginEdit : System.Windows.Forms.DataGridViewCellCancelEventHandler 
Public Custom Event CellBeginEdit As DataGridViewCellCancelEventHandler 

事件類型

範例

下列程式碼範例說明如何處理此事件,以反映正在編輯目前的 DataGridViewCell 。 在此範例中 Text ,包含 Form 的 屬性會設定為反映正在編輯的儲存格。 若要執行此範例,請將程式碼貼到包含 DataGridView 具名 dataGridView1 的表單中,並確定所有事件都與其事件處理常式相關聯。

private void dataGridView1_CellBeginEdit(object sender,
    DataGridViewCellCancelEventArgs e)
{
    string msg = String.Format("Editing Cell at ({0}, {1})",
        e.ColumnIndex, e.RowIndex);
    this.Text = msg;
}

private void dataGridView1_CellEndEdit(object sender,
    DataGridViewCellEventArgs e)
{
    string msg = String.Format("Finished Editing Cell at ({0}, {1})",
        e.ColumnIndex, e.RowIndex);
    this.Text = msg;
}
Private Sub dataGridView1_CellBeginEdit(ByVal sender As Object, _
    ByVal e As DataGridViewCellCancelEventArgs) _
    Handles DataGridView1.CellBeginEdit

    Dim msg As String = _
        String.Format("Editing Cell at ({0}, {1})", _
        e.ColumnIndex, e.RowIndex)
    Me.Text = msg

End Sub

Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles DataGridView1.CellEndEdit

    Dim msg As String = _
        String.Format("Finished Editing Cell at ({0}, {1})", _
        e.ColumnIndex, e.RowIndex)
    Me.Text = msg

End Sub

備註

如需如何處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱