DataGridViewCellValidatingEventHandler デリゲート
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Delegate Sub DataGridViewCellValidatingEventHandler ( _ sender As Object, _ e As DataGridViewCellValidatingEventArgs _ )
public delegate void DataGridViewCellValidatingEventHandler ( Object sender, DataGridViewCellValidatingEventArgs e )
public delegate void DataGridViewCellValidatingEventHandler ( Object^ sender, DataGridViewCellValidatingEventArgs^ e )
/** @delegate */ public delegate void DataGridViewCellValidatingEventHandler ( Object sender, DataGridViewCellValidatingEventArgs e )

CellValidating イベントは、セルが入力フォーカスを失い、内容の検証が有効になった場合に発生します。このイベントをキャンセルすると、現在のセルへの変更がキャンセルされます。このイベントがデータ バインド モードでキャンセルされた場合、新しい値は基になるデータ ソースにはプッシュされません。このイベントが仮想モードでキャンセルされた場合、CellValuePushed イベントは発生しません。
DataGridViewCellValidatingEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataGridViewCellValidatingEventHandler デリゲートのページへのリンク