Public Class frmMain
Dim bm As BindingManagerBase 'this manages bound controls on this form
Dim newRecord As Boolean = False 'this is a flag to toggle adding a new record or not in the DoUpdate method in myADO class
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim result As Boolean = False
result = myADO.FillDB()
If Not result Then
MsgBox("I could not read the database...", MsgBoxStyle.Critical, "System Message")
Me.Close()
Else
bm = Me.BindingContext(myADO.dataSet, "customers") 'set the forms binding context manager to your dataset
bm.Position = 0 'start at first record
BindMyControls()
End If
End Sub
Private Sub BindMyControls()
'---this sub connects (binds) each textbox to a specific field in the dataset table
txtCustID.DataBindings.Add("Text", myADO.dataSet, "Customers.CustID")
txtLast.DataBindings.Add("Text", myADO.dataSet, "Customers.LastName")
txtFirst.DataBindings.Add("Text", myADO.dataSet, "Customers.FirstName")
txtStreet.DataBindings.Add("Text", myADO.dataSet, "Customers.StreetAddress")
txtCity.DataBindings.Add("Text", myADO.dataSet, "Customers.City")
txtState.DataBindings.Add("Text", myADO.dataSet, "Customers.State")
txtZip.DataBindings.Add("Text", myADO.dataSet, "Customers.Zip")
End Sub
'''
''' This sub handles click events for the navigation buttons. I defined those in the properties of each button. I
''' told VS to redirect each click event to this one. I created one click event then renamed it to "NavigationButton_Click".
'''
'''
'''
'''
Private Sub NavigationButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnFirst.Click, btnPrevious.Click, btnNext.Click, btnLast.Click
Dim whichButton As Button = CType(sender, Button)
'---moves to the record they want
Select Case whichButton.Name.ToString
Case "btnFirst"
bm.Position = 0
Case "btnPrevious"
bm.Position -= 1
Case "btnNext"
bm.Position += 1
Case "btnLast"
bm.Position = myADO.dataSet.Tables(0).Rows.Count
End Select
End Sub