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
[/code][/code]ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
should it have a dot between?
ASKER
this part is underlined red: DataGridViewStringsBulk.Se lectedRows (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?
ASKER
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
replace it with :
x = DataGridViewStringsBulk.SelectedRows(i).Cells("Strshort").Value
ASKER
yes that got it.
ASKER