Vb.net 2008 Datagridview selected

I got 1 datagridview with 4 column and many row.if user select one row of datagridview.
how to retrive string value for each column?
aaronthamAsked:
Who is Participating?
 
Jorge PaulinoIT Pro/DeveloperCommented:
This will give the value for the first column of the selected row. You just need to change the 0 to 1, 2 and 3 for the other ones
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        If Me.DataGridView1(0, e.RowIndex).Value IsNot Nothing Then
            Debug.WriteLine(Me.DataGridView1(0, e.RowIndex).Value.ToString)
        End If
    End Sub

Open in new window

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
This shows all values
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        For Each col As DataGridViewColumn In Me.DataGridView1.Columns
            Debug.WriteLine(Me.DataGridView1(col.Index, e.RowIndex).Value)
        Next
    End Sub

Open in new window

0
 
JackOfPHCommented:

Private Sub RetrieveValueOfCell()

For each row as datagridviewrow in DataGridView1.SelectedRows
     msgbox(Row.Cells(0).value)  'Retrieve the first cell
     msgbox(Row.Cells(1).value)  'Retrieve the first cell
Next

End Sub
0
 
JackOfPHCommented:
Private Sub RetrieveValueOfCell()

For each row as datagridviewrow in DataGridView1.SelectedRows
     msgbox(Row.Cells(0).value)  'Retrieve the first cell
     msgbox(Row.Cells(1).value)  'Retrieve the Second cell
Next

End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.