I have two datagridviews, namely DataGV1 and DataGV2... when I click the next button, on DataGV1, it runs as desired... and so on until the last row in DataGV1... and click the next button next to read the row on DataGV2.. . but he didn't take row index 0, he read into the second row in DataGV2...
Private Sub NextBtn_Click(sender As Object, e As EventArgs) Handles NextBtn.Click... ...Dim lrData1 As Integer = DataGV1.Rows.Count - 1, lrData2 As Integer = ...DataGV2.Rows.Count - 1... ...Dim a As Integer, price As Decimal, lr As Integer = lrData1 + lrData2... ...Dim row1 As Integer, row2 As Integer... ...a = rowDataTXT.Text... ...If a >= 0 And a < lrData1 Then... ...If DataGV1.CurrentCell.Selected = False Then... ...DataGV1.CurrentCell.Selected = True... ...row1 = DataGV1.SelectedRows(0).Index... ...a = -1... ...Else... ...row1 = DataGV1.SelectedRows(0).Index + 1... ...End If...** If row1 <= DataGV1.Rows.Count - 2 Then Dim nextRow As DataGridViewRow = DataGV1.Rows(row1 ) DataGV1.CurrentCell = nextRow.Cells(0) DataGV1.Rows(row1 ).Selected = True End If Dim i As Integer = DataGV1.SelectedRows(0).Index If i >= 0 AndAlso i < DataGV1.Rows.Count - 1 Then itemTxt.Text = DataGV1(0, i).Value.ToString stokAlreadyTXT.Text = DataGV1(1, i).Value.ToString priceTXT.Text = DataGV1(2, i).Value.ToString price = DataGV1(2, i).Value End If a += 1 End If If a >= lrData1And a < lrData1 + lrData2 Then DataGV1.CurrentRow.Selected = False Me.TabControl1.SelectedTab = TabPage2 If a = lrData1 Then DataGV2.Rows(0).Selected = True row2 = DataGV2.SelectedRows(0).Index Else a = lrData2 row2 = DataGV2.SelectedRows(0).Index + 1 End If If row2 <= DataGV2.Rows.Count - 2 Then Dim nextRow As DataGridViewRow = DataGV2.Rows(row2 ) DataGV2.CurrentCell = nextRow.Cells(0) DataGV2.Rows(row2 ).Selected = True End If Dim i As Integer = DataGV2.SelectedRows(0).Index If i >= 0 AndAlso i < DataGV2.Rows.Count - 1 Then itemTxt.Text = DataGV2(0, i).Value.ToString stokAlreadyTXT.Text = DataGV2(1, i).Value.ToString priceTXT.Text = DataGV2(2, i).Value.ToString price = DataGV2(2, i).Value End If a += row2 End If rowDataTXT.Text = a End Sub Private Sub backBtn_Click(sender As Object, e As EventArgs) Handles backBtn.Click Dim lrData1 As Integer = DataGV1.Rows.Count - 1, lrData2 As Integer = DataGV2.Rows.Count - 1 Dim a As Integer, price As Decimal, lr As Integer = lrData1 + lrData2, row2 As Integer, row1 As Integer a = rowDataTXT.Text If a >= 0 And a <= lrData1 Then TabControl1.SelectedTab = TabPage1 If DataGV1.CurrentCell.Selected = False Then DataGV1.CurrentCell.Selected = True row1 = DataGV1.SelectedRows(0).Index + lrData1 Else row1 = DataGV1.SelectedRows(0).Index - 1 End If If row1 >= 0 And row1 <= DataGV1.Rows.Count - 2 Then Dim nextRow As DataGridViewRow = DataGV1.Rows(row1 ) DataGV1.CurrentCell = nextRow.Cells(0) DataGV1.Rows(row1 ).Selected = True End If Dim i As Integer = DataGV1.SelectedRows(0).Index If i >= 0 AndAlso i < DataGV1.Rows.Count - 1 Then itemTxt.Text = DataGV1(0, i).Value.ToString stokAlreadyTXT.Text = DataGV1(1, i).Value.ToString priceTXT.Text = DataGV1(2, i).Value.ToString price = DataGV1(2, i).Value End If a -= 1 End If If a > lrData1 And a <= lrData1 + lrData2 Then Me.TabControl1.SelectedTab = TabPage2 row2 = DataGV2.SelectedRows(0).Index - 1 If row2 >= 0 And row2 <= DataGV2.Rows.Count - 2 Then Dim nextRow As DataGridViewRow = DataGV2.Rows(row2 ) DataGV2.CurrentCell = nextRow.Cells(0) DataGV2.Rows(row2 ).Selected = True End If Dim i As Integer = DataGV2.SelectedRows(0).Index If i >= 0 AndAlso i < DataGV2.Rows.Count - 1 Then itemTxt.Text = DataGV2(0, i).Value.ToString stokAlreadyTXT.Text = DataGV2(1, i).Value.ToString priceTXT.Text = DataGV2(2, i).Value.ToString price = DataGV2(2, i).Value End If a -= 1 End If rowDataTXT.Text = a End Sub