Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im having this problem, When i click the ID in the datagridview all the textbox control is changing data but the numericUpDown is not. THANKS IN ADVANCE


customerID = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
           textBox1.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
           textBox2.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
           textBox3.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
           textBox4.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
          numericUpDown1.Value =  dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
           numericUpDown2.Value = dataGridView1.SelectedRows[0].Cells[6].Value.ToString();


What I have tried:

I Tried to use ToString to convert the numeric but still not working.
Posted
Updated 27-Mar-20 3:35am

1 solution

NumericUpDown does not accept string values. See: Set and Return Numeric Values with NumericUpDown Control - Windows Forms | Microsoft Docs[^]

Change your code as follow:
C#
numericUpDown1.Value =  (int)dataGridView1.SelectedRows[0].Cells[5].Value;
numericUpDown2.Value = (int)dataGridView1.SelectedRows[0].Cells[6].Value;


[EDIT]
Dave, thank you very much for improvement.
[/EDIT]
 
Share this answer
 
v3
Comments
CPallini 27-Mar-20 9:51am    
5.
Maciej Los 27-Mar-20 10:05am    
Thank you very much, Carlo.
oceanotrash 27-Mar-20 10:15am    
Still has an error it says "Cannot implicitly convert type 'object' to 'decimal' "
Dave Kreskowiak 27-Mar-20 10:18am    
Cells[].Value returns an Object, so you have to cast the value back to the type youi need:
numericUpdateDown1.Value = (int)dataGridView1.SelectedRows[0].Cells[5].Value;
oceanotrash 27-Mar-20 10:37am    
IT FINALLY WORKED!!! Thank you for your help sir and and to those who bother to comment i really appreciate it!!! I've been dealing this problem whole day so this is a relief for me THANK YOU once again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900