DataGridView.CellEndEdit イベント

定義

現在選択されているセルに対して、編集モードが停止されたときに発生します。

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

イベントの種類

次のコード例は、イベント ハンドラーによって以前に設定された場合に、このイベントを処理して行 DataGridViewRow.ErrorText プロパティをクリアする方法を CellValidating 示しています。 イベント ハンドラーは CellValidating 、新しいセル値が検証条件を満たしている場合にエラー テキストをクリアできますが、ユーザーが ESC キーを押して古いセル値に戻ると、 CellValidating イベントは発生しません。 この例は、「チュートリアル: Windows フォーム DataGridView コントロールでのデータの検証」で使用できるより大きな例の一部です。

private void dataGridView1_CellValidating(object sender,
    DataGridViewCellValidatingEventArgs e)
{
    string headerText = 
        dataGridView1.Columns[e.ColumnIndex].HeaderText;

    // Abort validation if cell is not in the CompanyName column.
    if (!headerText.Equals("CompanyName")) return;

    // Confirm that the cell is not empty.
    if (string.IsNullOrEmpty(e.FormattedValue.ToString()))
    {
        dataGridView1.Rows[e.RowIndex].ErrorText =
            "Company Name must not be empty";
        e.Cancel = true;
    }
}

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    // Clear the row error in case the user presses ESC.   
    dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
    ByVal e As DataGridViewCellValidatingEventArgs) _
    Handles dataGridView1.CellValidating

    Dim headerText As String = _
        dataGridView1.Columns(e.ColumnIndex).HeaderText

    ' Abort validation if cell is not in the CompanyName column.
    If Not headerText.Equals("CompanyName") Then Return

    ' Confirm that the cell is not empty.
    If (String.IsNullOrEmpty(e.FormattedValue.ToString())) Then
        dataGridView1.Rows(e.RowIndex).ErrorText = _
            "Company Name must not be empty"
        e.Cancel = True
    End If
End Sub

Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
    Handles dataGridView1.CellEndEdit

    ' Clear the row error in case the user presses ESC.   
    dataGridView1.Rows(e.RowIndex).ErrorText = String.Empty

End Sub

注釈

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

適用対象

こちらもご覧ください