I'm working on making a basic program that will allow me to move through database records, and when the user is at the last record to disable the next/last record buttons, same thing with the previous/first record buttons. Here is what I've done to try and accomplish this;
I made 2 methods and call them when the button is pressed, this doesent work atm. The problems with it are; if you hit btnToEnd it will jump to the last record but wont grey out the button until you press next again. Same thing happens with the btnToStart.
Code:Private Sub MaxRecord() If recordCount > Me.TblStudentsBindingSource.Count - 1 Then btnToEnd.Enabled = False btnNext.Enabled = False Else btnToEnd.Enabled = True btnNext.Enabled = True recordCount = recordCount + 1 End If End Sub Private Sub MinRecord() If Me.TblStudentsBindingSource.Position() = 0 Then btnToStart.Enabled = False btnPrevious.Enabled = False Else btnToStart.Enabled = True btnPrevious.Enabled = True recordCount = recordCount - 1 End If End Sub Private Sub TblStudentsBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblStudentsBindingNavigatorSaveItem.Click Me.Validate() Me.TblStudentsBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.StudDataDataSet) End Sub Private Sub btnToStart_Click(sender As Object, e As EventArgs) Handles btnToStart.Click MaxRecord() Me.TblStudentsBindingSource.MoveFirst() 'Moves to the First Record MaxRecord() 'Me.TblStudentsBindingSource.Position() to check position of record 'Me.TblStudentsBindingSource.Count()-1 for button disable '.filter to find records End Sub Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click MinRecord() Me.TblStudentsBindingSource.MovePrevious() 'Moves back 1 record MinRecord() End Sub Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click MaxRecord() Me.TblStudentsBindingSource.MoveNext() MaxRecord() End Sub Private Sub btnToEnd_Click(sender As Object, e As EventArgs) Handles btnToEnd.Click MaxRecord() Me.TblStudentsBindingSource.MoveLast() MaxRecord() End Sub




Reply With Quote
