DataGridViewCellValidatingEventArgs クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


DataGridView.CellValidating イベントを使用すると、新しい値が有効でない場合に、現在のセルに対する変更をキャンセルできます。現在の値を確認するには、FormattedValue プロパティを使用します。現在のセルの状態を確認するには、RowIndex プロパティと ColumnIndex プロパティを使用して、DataGridView.Rows コレクションを通じてセルにアクセスします。変更をキャンセルするには、Cancel プロパティを true に設定します。
このイベントがデータ バインド モードでキャンセルされた場合、新しい値は基になるデータ ソースにはプッシュされません。このイベントが仮想モードでキャンセルされた場合、DataGridView.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

System.EventArgs
System.ComponentModel.CancelEventArgs
System.Windows.Forms.DataGridViewCellValidatingEventArgs


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridViewCellValidatingEventArgs メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridView.CellValidating イベント
DataGridView.CellValidated イベント
DataGridView.CellValuePushed イベント
DataGridView.OnCellValidating
DataGridViewCell クラス
DataGridViewCellValidatingEventHandler
FormattedValue
RowIndex
ColumnIndex
CancelEventArgs.Cancel
- DataGridViewCellValidatingEventArgs クラスのページへのリンク