LeighWardle
asked on
VB.NET - DataGridView control throws errors when attempting to set cells empty or blank
Hi Experts,
I've got a DataGridView control that includes some columns that are bound to Double fields in my database.
When I edit any of these cells so that they are empty or blank I get this error:
How can I fix these errors?
I don't really mind if the cells display as empty, blank or 0.
Regards,
Leigh
I've got a DataGridView control that includes some columns that are bound to Double fields in my database.
When I edit any of these cells so that they are empty or blank I get this error:
The following exception occurred in the DataGridView:
System.FormatException: Input string was not in a correct format. —> System.FormatException: Input string was not in a correct format.
at System.Number.ParseDoubleString value, NumberStyles options, NumberFormatlnfo numfmt) at System.Double.Parse(String s, NumberStyles style, IFormatProvider provider)
— End of inner exception stack trace — at
System.Windows.Forms.Formatter.lnvokeStringParseMethod( Object value, Type targetType, IFormatProvider formatlnfo) at
System.Windows.Forms.Formatter.ParseObjectlnternal(Object value, Type targetType, Type sourceType, TypeConverter targetConverter, TypeConverter sourceConverter, IFormatProvider formatlnfo, Object formattedNullValue) at System.Windows.Forms.Formatter.ParseObject(Object value, Type targetType, Type sourceType, TypeConverter targetConverter, TypeConverter sourceConverter, IFormatProvider formatlnfo, Object formattedNullValue,
Object dataSourceNullValue) at
System.Windows.Forms.DataGridViewCell.ParseFormattedValu elnternalfType valueType, Object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) at
System.Windows.Forms.DataGridViewCell.ParseFormattedValu e(Object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) at
System.Windows.Forms.DataGridView.PushFormattedValuefDa taGridViewCell& dataGridViewCurrentCell, Object formattedValue, Exception& exception)
To replace this default dialog please handle the DataError event.
How can I fix these errors?
I don't really mind if the cells display as empty, blank or 0.
Regards,
Leigh
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would have changed the table definition to allow nulls but that works. I don't ever allow nullstrings in tables because it means that I need to work differently with numeric/date and text fields.
ASKER
I did a bit more experimenting.
I found a fix for my problem by opening the DataGridView in the Designer and setting the NullValue to an empty string.
Now I can delete content of any of those cells without the error.
Next time the grid is displayed the deleted cells appear as 0.0
Regards,
Leigh