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

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

DataError イベントは、データ バインド DataGridView でデータ処理時にエラーが発生したとき (書式指定操作や解析操作が例外をスローしたとき、またはデータ ソースの更新が失敗したときなど) に発生します。
DataGridViewDataErrorEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

次のコード例は、DataGridViewDataErrorEventHandler を使用して、DataError に関する情報をメッセージ ボックスに表示する方法を示しています。このコードは、DataGridViewComboBoxColumn クラスの概要に関するトピックで取り上げているコード例の一部分です。
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; } }

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


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