DataGridView DateTimeColumn DBNull error

Answered
0
0

Hi

Using version 2.2.40

When adding a new row to a data bound DGV which contains a DateTimePicker column I get the attached error.

Works fine if the row already exists

Thanks for your help

Ewan

Attachment
  • Ewan Walker
    Hi Luca, Frank has a demo project I sent not too long ago. This demonstrates the same issue when run using the latest version. It was sent on 22nd Jan and copied to support. The issue then was https://wisej.com/support/question/datagridview-sort-error
  • Luca
    • Luca
    • Mar 4, 2021 - 8:59 pm
    Yes got it. The regression was in the automatic row.
  • You must to post comments
Best Answer
0
0

Hi Luca

The framework DLL you sent me has fixed the issue

Thanks for your help

  • You must to post comments
0
0

Hi Ewan,

I cannot reproduce. Tried this to add null and DBValue.Null  to a DateTime column in a DataTable.

 var t = new DataTable();
 t.Columns.Add("C1", typeof(DateTime));
 t.Columns.Add("C2", typeof(Decimal));
 t.Columns.Add("C3", typeof(Boolean));
 t.Rows.Add(null, null, null);
 t.Rows.Add(DBNull.Value, DBNull.Value, null);
 t.Rows.Add(DateTime.Now, 5.5m, true);

Population works ok. Then on a click:

 dt.Rows.Add(null, null, null);
 dt.Rows.Add(DBNull.Value, DBNull.Value, null);

Which also works fine. Tried the same in winforms too.

Do you have a CellStyle or column.DefaultCellStyle saved in InitializeComponent() or in code? The main fix related to the previous issue you reported was that the DataGridViewColumn defined the wrong DefaultCellStyle.DataSourceNullValue = DateTime.MinValue when it should have been DefaultCellStyle.DataSourceNullValue = DBNull.Value.

Can you send me directly a reproducible case or a code snippet? Use my email address. I’d like to address this issue.

 

 

Attachment
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.