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


DataError イベントを使用すると、コントロール外のコード (外部データ ソースなど) によりスローされた例外を処理できます。Context プロパティを使用して、例外が発生したときの DataGridView の状態を調べます。Exception プロパティを使用して、例外データを取得します。追加のイベント ハンドラを使用して例外を処理するには、ThrowException プロパティを true に設定します。

DataGridViewDataErrorEventArgs クラスにより得られた情報に応答する方法を次のコード例に示します。
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
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: 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; } }

System.EventArgs
System.ComponentModel.CancelEventArgs
System.Windows.Forms.DataGridViewCellCancelEventArgs
System.Windows.Forms.DataGridViewDataErrorEventArgs


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


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

Public Sub New ( _ exception As Exception, _ columnIndex As Integer, _ rowIndex As Integer, _ context As DataGridViewDataErrorContexts _ )
Dim exception As Exception Dim columnIndex As Integer Dim rowIndex As Integer Dim context As DataGridViewDataErrorContexts Dim instance As New DataGridViewDataErrorEventArgs(exception, columnIndex, rowIndex, context)
public DataGridViewDataErrorEventArgs ( Exception exception, int columnIndex, int rowIndex, DataGridViewDataErrorContexts context )
public: DataGridViewDataErrorEventArgs ( Exception^ exception, int columnIndex, int rowIndex, DataGridViewDataErrorContexts context )
public DataGridViewDataErrorEventArgs ( Exception exception, int columnIndex, int rowIndex, DataGridViewDataErrorContexts context )
public function DataGridViewDataErrorEventArgs ( exception : Exception, columnIndex : int, rowIndex : int, context : DataGridViewDataErrorContexts )

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


DataGridViewDataErrorEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。) |
![]() | ColumnIndex | イベントが発生したセルの列インデックスを取得します。 ( DataGridViewCellCancelEventArgs から継承されます。) |
![]() | Context | エラーが発生したときの DataGridView の状態の詳細を取得します。 |
![]() | Exception | エラーを表す例外を取得します。 |
![]() | RowIndex | イベントが発生したセルの行インデックスを取得します。 ( DataGridViewCellCancelEventArgs から継承されます。) |
![]() | ThrowException | DataGridViewDataErrorEventHandler デリゲートが終了した後に例外をスローするかどうかを示す値を取得または設定します。 |

DataGridViewDataErrorEventArgs メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

DataGridViewDataErrorEventArgs メンバ
DataGridViewDataErrorEventArgs データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。) |
![]() | ColumnIndex | イベントが発生したセルの列インデックスを取得します。(DataGridViewCellCancelEventArgs から継承されます。) |
![]() | Context | エラーが発生したときの DataGridView の状態の詳細を取得します。 |
![]() | Exception | エラーを表す例外を取得します。 |
![]() | RowIndex | イベントが発生したセルの行インデックスを取得します。(DataGridViewCellCancelEventArgs から継承されます。) |
![]() | ThrowException | DataGridViewDataErrorEventHandler デリゲートが終了した後に例外をスローするかどうかを示す値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- DataGridViewDataErrorEventArgsのページへのリンク