2

Im trying to return the value contained in a datagridview cell upon clicking on the cell. can anyone please show me how to do this using vb.net?thanks

2 Answers 2

11

Check this sample code. The key is to use the event's DataGridViewCellEventArgs parameter to find the clicked cell's RowIndex and ColumnIndex.

Private Sub DataGridView1_CellClick(ByVal sender As System.Object, _
                                    ByVal e As DataGridViewCellEventArgs) _
                                    Handles DataGridView1.CellClick
    MsgBox(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
End Sub
1
  • P.S: You will probably get more answers if you actually bother to mark the answer which helped you most - Reputation is the only reward for those answering you.
    – M.A. Hanin
    Mar 15, 2010 at 13:39
0

You can call from a button

Dim y As String = DataGridView1.CurrentCell.Value

If IsDBNull(y) Then

Else

TextBox1.Text = y

End If

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.