DataGrid, cannot enter DBNull/blank via UI, can in code.

Sep 13, 2010 at 4:18 PM

My DataGrid is bound to a DataTable. The DataTable has numeric types which AllowDBNull.


gridDataTable = new DataTable("MyDataTable");
gridDataTable.Columns.Add(new DataColumn("LowCutOff", typeof(double)));
gridDataTable.Columns[4].AllowDBNull = true;
gridDataTable.Columns[4].DefaultValue = DBNull.Value;
columnsGrid.ItemsSource = gridDataTable.DefaultView;

I can add rows to the DataTable/Grid which have DBNulls via code no problem, like this...

gridDataTable.Rows.Add("", TypeCode.Double, "", false, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);

But there is no way I can enter null numeric values through the UI. Leaving a cell blank is the same as leaving non-numeric text in the cell, it goes into an error mode and I can't input normally after that.

Even buggering around with the CellEditEnding event for hours hasn't solved the problem even though I've updated the underlying DataTable successfully withe the DBNull value for that location. The interface still thinks it's in an error state after that and the editcancel won't fix that either.

Any ideas?

(Go back to WinForms??)