Editing a numeric value in an unbound DataGridView changes the value type for the cell

Answered
0
0

On the basis of my last question around unbound DataGridView’s this could be me….

I have a numeric column in my DGV and I’ve set its type to Int32. If I do not edit the value I can retrieve the value as an int but if I edit the cell the value changes to a decimal.

I may be retrieving the value incorrectly so I’ve attached an updated sample.

When you run the sample:

  • Click button 1 – you will get a MessageBox showing the value of  quantity in the first row.
  • Click on the quantity cell in the first row and change the value
  • Click button 1 again and you will get an exception as the int is now a decimal.

Thanks

Nic

  • You must to post comments
Best Answer
0
0

Nic,

the bug has been logged as WJ-8910 and is fixed in the latest release (1.4.95)

Best regards
Frank

  • Nic Adams
    Thanks Frank – it is now working as expected.
  • You must to post comments
0
0

There is a difference between DataGridViewNumericUpDownColumn and DataGridViewNumericUpDownCell. The column type allows you to change the value type, while the NumericUpDown cell is set to decimal since the NumericUpDown control’s value property is also decimal. Will log the bug.

 

Also Wisej allows cells of different types to be mixed in the same column. i.e. a column could contain a datetime cell and a combobox cell, etc.

It’s easy to set up a column/cell with the Int32 value type like this:

class DataGridViewInt32Column : DataGridViewNumericUpDownColumn
{
public DataGridViewInt32Column() { this.CellTemplate = new DataGridViewInt32Cell(); }
}

class DataGridViewInt32Cell : DataGridViewNumericUpDownCell
{
public override Type ValueType { get { return typeof(int); } }
}

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.