Extract datagridview value (generated through SELECT) to integrate it in TEXTBOX

0

I try to extract the value from Row to add it to the Textbox.

Thank you in advance.

    
asked by Daniel 23.04.2018 в 06:57
source

1 answer

3

First, the collection Rows of DataGridView is a collection of type DataGridViewRow . This means that when you get the dgvVentaFinal.Rows[2] value, you are getting a DataGridViewRow , that is, a whole grid row. Obviously, that type can not be converted to Int32 .

To obtain a value, you must specify in which row it is, but also in what cell ( Cell ), with what you have to access in the following way:

dgvVentaFinal.Rows[2].Cells[0]

In this way you access row 2, column 0. But still, what you get is a value of type DataGridViewCell , that is, you access the cell (which has many properties), but not its value. To access the value, you must obtain the property Value of DataGridViewCell :

dgvVentaFinal.Rows[2].Cells[0].Value

Now if you have the courage. Another strange thing is that you make a conversion to Int32 when what you are going to do is show the value in a TextBox , which will result in an implicit conversion. So finally your code should be as follows:

txtSubTotal.Text = dgvVentaFinal.Rows[2].Cells[0].Value.ToString();
    
answered by 23.04.2018 в 10:00