Error editing numeric cell when using unbound DataGridView

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
Answered
0
0

I’m not sure I am setting this up correctly so I’ve attached a simple sample app to show the problem.

I’m programmatically adding rows to a DataGridView. Double clicking on one of the Quantity cells or typing a number whilst one is selected causes an error.

Value of ‘0’ is not valid for ‘Value’. ‘Value’ should be between 1 and 100.
Parameter name: Value

Thanks

Nic

  • Luca (ITG)
    Attachment is truncated.
  • Nic Adams
    Sorry – I’ve re-uploaded it.
  • You must to post comments
Best Answer
0
0

You are using the DataGridViewNumericUpDownColumn which takes in values. But the code assigns string values. Also the NumericUpDown editor has its value range between 0 and 100 by default. You can change that setting the properties of the column.

In alternative you can use the DataGridViewTextBoxColumn and set the ValueType to int to force the integere data conversion.

This change works in your test case:

dataGridView1.Rows.Add(“Item 1”, 4);
dataGridView1.Rows.Add(“Item 2”, 3);
dataGridView1.Rows.Add(“Item 3”, 2);
dataGridView1.Rows.Add(“Item 4”, 1);

  • Nic Adams
    Perfect – I told you it was me!
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 5, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json mixin.theme