hello,
I have a datagridview on my form that is populated with thousands of records from a database. When I add a new product, I want the new product to be the one selected. I've tried aot of different things and cant seem to achieve this. The following HIGHLIGHTS the new row but not SELECT it.The first row is still selected (the little arrow cursor in the row header) is set on the first record. The DGV imulti select property is set to true for multiple edit.
[CODE]
Private Sub setSelectedRow( ByVal data As DataGridView)
Try
Dim counter As Integer = 1
data.ClearSelec tion()
For counter = 1 To data.Rows.Count
If data.Rows(count er - 1).Cells(colNam e).Value.ToStri ng.Trim = colValue Then
data.Rows(count er - 1).Cells(1).Sel ected = True
data.Rows.Item( counter - 1).Selected = True
Exit For
End If
Next
'Scroll to the selected row in case it was hidden.
data.FirstDispl ayedScrollingRo wIndex = counter - 1
Catch ex As Exception
MsgBox("set row error " & ex.Message)
End Try
[CODE]
Any help is deeply appreciated. Thanks in advance
I have a datagridview on my form that is populated with thousands of records from a database. When I add a new product, I want the new product to be the one selected. I've tried aot of different things and cant seem to achieve this. The following HIGHLIGHTS the new row but not SELECT it.The first row is still selected (the little arrow cursor in the row header) is set on the first record. The DGV imulti select property is set to true for multiple edit.
[CODE]
Private Sub setSelectedRow( ByVal data As DataGridView)
Try
Dim counter As Integer = 1
data.ClearSelec tion()
For counter = 1 To data.Rows.Count
If data.Rows(count er - 1).Cells(colNam e).Value.ToStri ng.Trim = colValue Then
data.Rows(count er - 1).Cells(1).Sel ected = True
data.Rows.Item( counter - 1).Selected = True
Exit For
End If
Next
'Scroll to the selected row in case it was hidden.
data.FirstDispl ayedScrollingRo wIndex = counter - 1
Catch ex As Exception
MsgBox("set row error " & ex.Message)
End Try
[CODE]
Any help is deeply appreciated. Thanks in advance