英語で読む

次の方法で共有


DataGridView.CellEndEdit イベント

定義

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

C#
public event System.Windows.Forms.DataGridViewCellEventHandler CellEndEdit;
C#
public event System.Windows.Forms.DataGridViewCellEventHandler? CellEndEdit;

イベントの種類

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

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

注釈

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

適用対象

製品 バージョン
.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

こちらもご覧ください