move to previous/next record casues 'System.Data.DataRowView' to display in key field

129 views Asked by At

Help! I'm trying to navigate previous/next through records (MS Access backend database) in a bound form. Note, this is a DataRowView (individually bound fields), not a DataGridView. I've got two related issues, but I'll handle the second issue in another post. I've got two key fields in the underlying database table. The second key field, Carrier_No, is defined as 5 characters. When I attempt to move to the previous record, the application populates the second key field with 'System.Data.DataRowView.' Then, when I click the Previous (or Next) button again, I get the following error: System.ArgumentException: 'Cannot set column 'Carrier_No'. The value violates the MaxLength limit of this column.' What am I doing wrong? This seems to be such a simple task.

1

There are 1 answers

0
Jeff S On

Thanks all for your responses. After much troubleshooting, I stumbled upon the solution. It turns out the combobox 'DropDownStyle' property was the culprit. I had originally set the property to 'DropDownList' to prevent users from entering a value. When I set the property to 'DropDown,' the problem went away. I have no idea why this property would have any effect on record navigation, but it does. To prevent users from entering data, I employed some code in the combobox 'KeyPress' event. As it turns out, this solution also solved a related issue (combobox values being copied to other records, separate post). Private Sub cmb_TPA_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cmb_TPA.KeyPress MsgBox("Please select a TPA value from the pick list.", vbExclamation) e.Handled = True 'cancel event End Sub