DataGridView.CellValidating イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim handler As DataGridViewCellValidatingEventHandler AddHandler instance.CellValidating, handler
public: event DataGridViewCellValidatingEventHandler^ CellValidating { void add (DataGridViewCellValidatingEventHandler^ value); void remove (DataGridViewCellValidatingEventHandler^ value); }

このイベントをキャンセルすると、現在のセルへの変更がキャンセルされます。このイベントがデータ バインド モードでキャンセルされた場合、新しい値が、基になるデータ ソースにプッシュされることはありません。このイベントが仮想モードでキャンセルされた場合、CellValuePushed イベントは発生しません。

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 Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridViewCellValidatingEventHandler
DataGridViewCellValidatingEventArgs
DataGridView.CellValidated イベント
DataGridViewCell
OnCellValidating
その他の技術情報
DataGridView コントロール (Windows フォーム)
- DataGridView.CellValidating イベントのページへのリンク