Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

get column data from selected row vb.net

I have this code that gets the count of selected rows ok but I want the string of whats shown on the attached as opposed to the index number of the row. not sure how to do that.

[code][code]
    Private Sub PanelLinkShort_Click(sender As Object, e As EventArgs) Handles PanelLinkShort.Click


        Dim selectedRowCount As Integer =
           DataGridViewStringsBulk.Rows.GetRowCount(DataGridViewElementStates.Selected)
        Dim x As String
        If selectedRowCount > 0 Then

            Dim i As Integer
            For i = 0 To selectedRowCount - 1

                'get rows
                x = DataGridViewStringsBulk.SelectedRows(i).Index.ToString()


            Next i


            MessageBox.Show("Finished")

        End If

    End Sub

Open in new window

[/code][/code]

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

thank you
should it have a dot between?
this part is underlined red: DataGridViewStringsBulk.SelectedRows(i)
what do you mean? I have copied the name of your control from your code so it should be good? Where have you placed the new line of code? Inside your loop I hope! What is the error message that you get?
it says it cannot be indexed because datagridviewrow has no default property

      If selectedRowCount > 0 Then

            Dim i As Integer
            For i = 0 To selectedRowCount - 1

                'get rows


                x = DataGridViewStringsBulk.SelectedRows(i)("Strshort").Value
            Next i


            MessageBox.Show("Finished")

        End If

Open in new window

replace it with :
x = DataGridViewStringsBulk.SelectedRows(i).Cells("Strshort").Value

Open in new window

yes that got it.