I'm using VB.NET 2008. I have an Bound DataGridView with a numeric 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?
A:
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.
Purple Ant
2009-12-16 19:59:54
No sure what code you would like to see?This is not really happening in the code the only place that I can intercept this error is in DataError Event and I'm not sure that there is away to know this specific error or how to tell it to by pass it or whether it is even ok to do this. I did try to replace the cell with a 0 but that did't take. It didn't give an error it just did change anything.
bochur1
2009-12-16 20:59:50
A:
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.
bochur1
2009-12-17 16:02:04