Setting DataGridView.DefaultCellStyle.NullValue to null during development increases the error when adding runtime rows

In Visual Studio 2008

  • add a new DataGridView to the form
  • Edit columns
  • Add New DataGridViewImageColumn
  • Open the CellStyle constructor of this column (DefaultCellStyle property)
  • Change NullValue from System.Drawing.Bitmap to null
  • Try adding a new row to the DataGridView at run time (DataGridView1.Rows.Add ();)
  • You get this error: System.FormatException: The formatted cell value is of the wrong type.

If you change the NullValue value to System.Drawing.Bitmap (as it was), you will still get the same error when adding a row.

If you set NullValue at run time instead of development time, you will not get anny error. (dataGridView1.Columns [0] .DefaultCellStyle.NullValue = null;)

Could you tell me why this is?

+3
source share
5 answers

This may be a mistake in the designer; if you look at the .designer.cs file (maybe make the difference before and after you set NullValue to null), you should see the code that it generates.

+2
source

Kronos is right. After installing it during development, he adds this to .designer.cs:

dataGridViewCellStyle1.NullValue = "null";

"null" null, . DataGridViewCellStyle.NullValue set_NullValue (Object) get_NullValue , , .

, , .design.cs.

+1

NullValue System.Drawing.Bitmap null

"null" NullValue , "null". NullValue - .

+1

String. IDE. "", RowsDefaultCellStyle.Format, . . , .

+1

, , . null. init .

0

Source: https://habr.com/ru/post/1696712/


All Articles