DataGridView.CellValidating イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.CellValidating イベントの意味・解説 

DataGridView.CellValidating イベント

メモ : このイベントは、.NET Framework version 2.0 で新しく追加されたものです。

セルが入力フォーカスを失い、内容の検証が有効になった場合に発生します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event CellValidating As
 DataGridViewCellValidatingEventHandler
Dim instance As DataGridView
Dim handler As DataGridViewCellValidatingEventHandler

AddHandler instance.CellValidating, handler
public event DataGridViewCellValidatingEventHandler CellValidating
public:
event DataGridViewCellValidatingEventHandler^ CellValidating {
    void add (DataGridViewCellValidatingEventHandler^ value);
    void remove (DataGridViewCellValidatingEventHandler^ value);
}
/** @event */
public void add_CellValidating (DataGridViewCellValidatingEventHandler
 value)

/** @event */
public void remove_CellValidating (DataGridViewCellValidatingEventHandler
 value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

CellValidating イベントを処理して、ユーザーが正の整数だけを入力するようにするコード例を次に示します。この例は VirtualMode のリファレンス トピックで取り上げている例の一部分です。

Private Sub dataGridView1_CellValidating(ByVal
 sender As Object, _
    ByVal e _
    As DataGridViewCellValidatingEventArgs) _
    Handles dataGridView1.CellValidating

    Me.dataGridView1.Rows(e.RowIndex).ErrorText = ""
    Dim newInteger As Integer

    ' Don't try to validate the 'new row' until finished 
    ' editing since there
    ' is not any point in validating its initial value.
    If dataGridView1.Rows(e.RowIndex).IsNewRow Then
 Return
    If Not Integer.TryParse(e.FormattedValue.ToString(),
 newInteger) _
        OrElse newInteger < 0 Then

        e.Cancel = True
        Me.dataGridView1.Rows(e.RowIndex).ErrorText = "the
 value must be a non-negative integer"

    End If
End Sub
private void dataGridView1_CellValidating(object
 sender,
    DataGridViewCellValidatingEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].ErrorText = "";
    int newInteger;

    // Don't try to validate the 'new row' until finished 
    // editing since there
    // is not any point in validating its initial value.
    if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return;
 }
    if (!int.TryParse(e.FormattedValue.ToString()
,
        out newInteger) || newInteger < 0)
    {
        e.Cancel = true;
        dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative
 integer";
    }
}
void VirtualConnector::dataGridView1_CellValidating
    (Object^ sender, DataGridViewCellValidatingEventArgs^ e)
{
    int newInteger;

    // Don't try to validate the 'new row' until finished 
    // editing since there
    // is not any point in validating its initial value.
    if (dataGridView1->Rows[e->RowIndex]->IsNewRow) 
    {
        return; 
    }
    if (!Int32::TryParse(e->FormattedValue->ToString(),
 
        newInteger) || (newInteger < 0))
    {
        e->Cancel = true;
    }
}
private void dataGridView1_CellValidating(Object
 sender,
    DataGridViewCellValidatingEventArgs e)
{
    int newInteger = 0;
    // Don't try to validate the 'new row' until finished 
    // editing since there
    // is not any point in validating its initial value.
    if (dataGridView1.get_Rows().get_Item(
        e.get_RowIndex()).get_IsNewRow()) {
        return;
    }
    if (!(Int32.TryParse(e.get_FormattedValue().ToString(), newInteger))
 
        || newInteger < 0) {
        e.set_Cancel(true);
    }
} //dataGridView1_CellValidating
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridViewCellValidatingEventHandler
DataGridViewCellValidatingEventArgs
DataGridView.CellValidated イベント
DataGridViewCell
OnCellValidating
その他の技術情報
DataGridView コントロール (Windows フォーム)


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataGridView.CellValidating イベントを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataGridView.CellValidating イベントを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataGridView.CellValidating イベント を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridView.CellValidating イベント」の関連用語

DataGridView.CellValidating イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.CellValidating イベントのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS