DataGridViewDataErrorEventArgs クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
DataError イベントのデータを提供します。
public ref class DataGridViewDataErrorEventArgs : System::Windows::Forms::DataGridViewCellCancelEventArgs
public class DataGridViewDataErrorEventArgs : System.Windows.Forms.DataGridViewCellCancelEventArgs
type DataGridViewDataErrorEventArgs = class
inherit DataGridViewCellCancelEventArgs
Public Class DataGridViewDataErrorEventArgs
Inherits DataGridViewCellCancelEventArgs
- 継承
例
次のコード例は、 クラスによって提供される情報に応答する方法を DataGridViewDataErrorEventArgs 示しています。 この例は、クラスの概要に関するトピックで使用できる大きな例の DataGridViewComboBoxColumn 一部です。
private:
void DataGridView1_DataError(Object^ sender, DataGridViewDataErrorEventArgs^ anError)
{
MessageBox::Show("Error happened " + anError->Context.ToString());
if (anError->Context == DataGridViewDataErrorContexts::Commit)
{
MessageBox::Show("Commit error");
}
if (anError->Context == DataGridViewDataErrorContexts::CurrentCellChange)
{
MessageBox::Show("Cell change");
}
if (anError->Context == DataGridViewDataErrorContexts::Parsing)
{
MessageBox::Show("parsing error");
}
if (anError->Context == DataGridViewDataErrorContexts::LeaveControl)
{
MessageBox::Show("leave control error");
}
if (dynamic_cast<ConstraintException^>(anError->Exception) != nullptr)
{
DataGridView^ view = (DataGridView^)sender;
view->Rows[anError->RowIndex]->ErrorText = "an error";
view->Rows[anError->RowIndex]->Cells[anError->ColumnIndex]->ErrorText = "an error";
anError->ThrowException = false;
}
}
private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs anError)
{
MessageBox.Show("Error happened " + anError.Context.ToString());
if (anError.Context == DataGridViewDataErrorContexts.Commit)
{
MessageBox.Show("Commit error");
}
if (anError.Context == DataGridViewDataErrorContexts.CurrentCellChange)
{
MessageBox.Show("Cell change");
}
if (anError.Context == DataGridViewDataErrorContexts.Parsing)
{
MessageBox.Show("parsing error");
}
if (anError.Context == DataGridViewDataErrorContexts.LeaveControl)
{
MessageBox.Show("leave control error");
}
if ((anError.Exception) is ConstraintException)
{
DataGridView view = (DataGridView)sender;
view.Rows[anError.RowIndex].ErrorText = "an error";
view.Rows[anError.RowIndex].Cells[anError.ColumnIndex].ErrorText = "an error";
anError.ThrowException = false;
}
}
Private Sub DataGridView1_DataError(ByVal sender As Object, _
ByVal e As DataGridViewDataErrorEventArgs) _
Handles DataGridView1.DataError
MessageBox.Show("Error happened " _
& e.Context.ToString())
If (e.Context = DataGridViewDataErrorContexts.Commit) _
Then
MessageBox.Show("Commit error")
End If
If (e.Context = DataGridViewDataErrorContexts _
.CurrentCellChange) Then
MessageBox.Show("Cell change")
End If
If (e.Context = DataGridViewDataErrorContexts.Parsing) _
Then
MessageBox.Show("parsing error")
End If
If (e.Context = _
DataGridViewDataErrorContexts.LeaveControl) Then
MessageBox.Show("leave control error")
End If
If (TypeOf (e.Exception) Is ConstraintException) Then
Dim view As DataGridView = CType(sender, DataGridView)
view.Rows(e.RowIndex).ErrorText = "an error"
view.Rows(e.RowIndex).Cells(e.ColumnIndex) _
.ErrorText = "an error"
e.ThrowException = False
End If
End Sub
注釈
イベントを DataError 処理すると、(たとえば外部データ ソースによって) コントロールの外部のコードによってスローされる例外を処理できます。 プロパティを Context 使用して、例外時の の DataGridView 状態を確認します。 例外データを Exception 取得するには、 プロパティを使用します。 追加のイベント ハンドラーによって例外を処理する場合は、 プロパティを ThrowException に true
設定します。
プロパティと RowIndex プロパティはColumnIndex、通常、データ エラーが発生したセルを示します。 ただし、外部データ ソースでエラーが発生した場合、データ ソースはエラーが発生した列を提供しない可能性があります。 この場合、 プロパティは ColumnIndex 通常、エラー発生時の現在のセルの列を示します。
コンストラクター
DataGridViewDataErrorEventArgs(Exception, Int32, Int32, DataGridViewDataErrorContexts) |
DataGridViewDataErrorEventArgs クラスの新しいインスタンスを初期化します。 |
プロパティ
Cancel |
イベントをキャンセルするかどうかを示す値を取得または設定します。 (継承元 CancelEventArgs) |
ColumnIndex |
イベントが発生したセルの列インデックスを取得します。 (継承元 DataGridViewCellCancelEventArgs) |
Context |
エラーが発生したときの DataGridView の状態の詳細を取得します。 |
Exception |
エラーを表す例外を取得します。 |
RowIndex |
イベントが発生したセルの行インデックスを取得します。 (継承元 DataGridViewCellCancelEventArgs) |
ThrowException |
DataGridViewDataErrorEventHandler デリゲートが終了した後に例外をスローするかどうかを示す値を取得または設定します。 |
メソッド
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
適用対象
こちらもご覧ください
.NET