VB.NET  •  Implement WinBar Behavior

Listing 1. This code implements the VCR control's basic features in a data form's WinBar by calling methods and properties of the DataContainer. The DataContainer includes most of the behavior you're likely to want to add to data forms.

Private Sub wbbtnFirst_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnFirst.Click
   Me.dcCustomers.MoveFirst()
End Sub

Private Sub wbbtnPrevious_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnPrevious.Click
   Me.dcCustomers.MovePrevious()
End Sub

Private Sub wbbtnNext_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnNext.Click
   Me.dcCustomers.MoveNext()
End Sub

Private Sub wbbtnLast_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnLast.Click
   Me.dcCustomers.MoveLast()
End Sub

Private Sub wbbtnPageDown_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnPageDown.Click
   Me.dcCustomers.Position += _
      Me.grdCustomers.DisplayedRowCount(False)
End Sub

Private Sub wbbtnPageUp_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnPageUp.Click
   Me.dcCustomers.Position -= _
      Me.grdCustomers.DisplayedRowCount(False)
End Sub

Private Sub dcCustomers_PositionChanged( _
   ByVal sender As Object, ByVal e As _
   System.EventArgs) Handles _
   dcCustomers.PositionChanged
   Me.wbtextPosition.Text = _
      CStr(Me.dcCustomers.Position + 1) & _
      " of " & CStr( _
      Me.dcCustomers.CurrencyManager.Count)
End Sub

Private Sub wbbtnFill_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnFill.Click
   Me.dcCustomers.LoadData()
End Sub

Private Sub wbbtnUndo_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs)
   Me.dcCustomers.CancelEdit()
End Sub

Private Sub wbbtnNew_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnNew.Click
   Me.dcCustomers.AddNew()
End Sub

Private Sub wbbtnDelete_Click(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   wbbtnDelete.Click
   Me.dcCustomers.Delete()
End Sub

Private Sub frmCustomer_Load(ByVal sender As _
   Object, ByVal e As System.EventArgs) Handles _
   MyBase.Load
   Application.EnableVisualStyles()
End Sub