[vb.net] How to get cell value from DataGridView in VB.Net?

I have a problem, how can i get value from cell of datagridview

----------------------------------
id     | p/w       | post       |
----------------------------------
1      |   1234    | A          |
----------------------------------
2      | 4567      | S          |
----------------------------------
3      | 6789      | A          |
----------------------------------

I want to get 3 into the textbox,how to do that? Can anyone give some example coding? than you~

This question is related to vb.net datagridview

The answer is


The line would be as shown below:

Dim x As Integer    
x = dgvName.Rows(yourRowIndex).Cells(yourColumnIndex).Value

To get the value of cell, use the following syntax,

datagridviewName(columnFirst, rowSecond).value

But the intellisense and MSDN documentation is wrongly saying rowFirst, colSecond approach...


In you want to know the data from de selected row, you can try this snippet code:

DataGridView1.SelectedRows.Item(0).Cells(1).Value

This helped me get close to what I needed and I will throw this out there for anyone else who needs it.

If you are looking for the value in the first cell in the selected column, you can try this. (I chose the first column, since you are asking for it to return "3", but you can change the number after Cells to get whichever column you need. Remember it is zero-based.)

This will copy the result to the clipboard: Clipboard.SetDataObject(Me.DataGridView1.CurrentRow.Cells(0).Value)


It is working for me

MsgBox(DataGridView1.CurrentRow.Cells(0).Value.ToString)

enter image description here