Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Returning DataSet value to null via user input

$
0
0

Setup:

Visual Studio 2008 Express SP1, Visual Basic 2008 Express

DataSet with Tables with Columns that allow Null values.

DataGridView bound to BindingSource bound to a table in the DataSet.

Issue:

Things seem to work until I try to set a cell back to blank.

The column for this cell is of Type Decimal.

The default value is <DBNull> and the cell is blank in a new row (and can be left blank).

I enter a numeric value in a blank cell and move to the next cell.

The cell formats with the correct number of decimal places.

I move back to the cell, delete the numeric text and attempt to move to the next cell again.

The DataGridView_Data Error event is called not allowing the cell to go back to blank.

Observations:

The error apparently occurs while parsing. The parsing formatter can’t format the empty string value from the blank cell in to a valid decimal value so throws the error.

Attempted work-arounds:

In the DataGridView_Parsing event I’ve tried conditionally setting the parsed value to dbNull.Value and to Nothing if the value to parse is an empty string. This doesn’t change the error.

I’ve also tried setting a form level variable to the value to parse in the DataGridView_Parsing event then, in the subsequent DataGridView_DataError event, if the e.Context includes .Parsing, setting e.ThrowException and e.Cancel to False when the saved parsing value was an empty string. This returns the cell value back to the value I’m trying to erase.

Question:

How do I get around this parsing error and have the DataSet value for this cell set back to Null when the DataGridView cell is set back to an empty string by the user?

Thanks,
Eric


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>