I am trying to write user friendly messages for when data integrity rules are broken in a DataGridView. I have handled the DataError error as per the code below but it does something odd when reading the column index of the DataGridViewDataErrorEventArgs. e.ColumnIndex = 2 but the e.Exception refers to the column at ColumnIndex = 3!
VB Code:
Private Sub AssetDataGridView_DataError(ByVal sender As Object, _ ByVal e As DataGridViewDataErrorEventArgs) Handles AssetDataGridView.DataError ' Get column name and header text from sender Dim colName As String = CType(sender, DataGridView).Columns(e.ColumnIndex).DataPropertyName Dim headerText As String = CType(sender, DataGridView).Columns(e.ColumnIndex).HeaderText ' Now replace column name with user-friendly header name Dim excMessage As String = e.Exception.Message
E.g. ? e.Exception.Message
"Column 'LocationID' does not allow nulls."
but
? colName
"AssetTypeID"
Not sure why this is happening - any help greatly appreciated.




Reply With Quote