DataGridView error when backspace on number column
I'm using VB.NET 2008. I have an Bound DataGridView with a numeri开发者_如何学Pythonc column that can be edited. However when one selects the number and backspaces there is an error. If I trap it in DataError Event the error message is "Input String was not in a correct format". How can I prevent this error?
If you could provide a small sample of your code it might be more helpful, but not having that i'd guess the application is trying to convert the empty string to a number, and it is failing. I'd say your best bet is to put a try/catch in the event that occurs when the data is being updated, and mark it as "handled" (check the EventArgs for a Handled property) to keep the error from being thrown. You'll then need to do your own error checking on the actual save code once the user is done editing the column.
Turns out the problem was that I had changed the DefaultCellStyle.NullValue. I changed it back to the default (Blank) and now everything is fine.
精彩评论