How are you loading the DGV, are you loading all the records from the table or are you calling the db for each record? How are you populating each cell of the DGV?
Count the rows returned from the db and then catch the row number to assign each record. This is how I do it in a form with controls, but the principle is the same.
Good luckCode:At form level declare these two variables ' declare a database cursor to point to the record Dim dbCursor As Integer = 0 ' declare a variable to hold the max number of records Dim MaxRecords As Integer ' Fill() is the method I use to populate a dataset, call yours whatever you want, remember do not just copy and past this into your form and expect it to work Private Sub btnFirstRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstRecord.Click ' error checking Try dbCursor = 0 Fill() Catch ex As Exception MsgBox("Error occurred in btnFirstRecord - Click event:" & ex.Message) End Try End Sub Private Sub btnPreviousRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousRecord.Click ' error checking Try If dbCursor <> 0 Then dbCursor = dbCursor - 1 Fill() End If Catch ex As Exception MsgBox("Error occurred in btnPreviousRecord - Click event:" & ex.Message) End Try End Sub Private Sub btnNextRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextRecord.Click ' error checking Try If dbCursor < MaxRecords - 1 Then dbCursor = dbCursor + 1 Fill() End If Catch ex As Exception MsgBox("Error occurred in btnNextRecord - Click event:" & ex.Message) End Try End Sub Private Sub btnLastRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLastRecord.Click ' error checking Try dbCursor = MaxRecords - 1 Fill() Catch ex As Exception MsgBox("Error occurred in btnLastRecord - Click event:" & ex.Message) End Try dbCursor = MaxRecords - 1 Fill() End Sub




Reply With Quote