■■■

2016年3月31日木曜日

DataGridViewの入力エラーを捕獲する方法

DataGridViewの入力エラーを捕獲する方法
VB.NET
Private Sub dgv1_DataError(ByVal sender As Object, _
ByVal e As DataGridViewDataErrorEventArgs) _
Handles dgv1.DataError
If Not (e.Exception Is Nothing) Then
MessageBox.Show(Me, _
String.Format("({0}, {1}) のセルエラー発生" + vbCrLf + vbCrLf + "{2}", _
e.ColumnIndex, e.RowIndex, e.Exception.Message), "エラー発生", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
End Sub
C#
private void dgv1_DataError(object sender,
DataGridViewDataErrorEventArgs e)
{
if (e.Exception != null)
{
MessageBox.Show(this,
string.Format("({0}, {1}) セルエラー発生 \n\n {2}",
e.ColumnIndex, e.RowIndex, e.Exception.Message),
"エラー発生",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
セルの入力エラーで元の値に自動で戻す方法
VB.NET
Private Sub dgv1_DataError(ByVal sender As Object, _
ByVal e As DataGridViewDataErrorEventArgs) _
Handles dgv1.DataError
e.Cancel = False
End Sub
C#
private void dgv1_DataError(object sender,
DataGridViewDataErrorEventArgs e)
{
e.Cancel = false;
}
















■■■