Imports System.Data
Public Class ExampleTwoForm
Private Sub ExampleTwoForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Make this form a MDI child of MainForm.
Me.MdiParent = My.Forms.MainForm
End Sub
' This code is called the BindingNavigator control's New button is clicked.
' Note: To prevent the BindingNavigator from automatically adding a new row
' when the New button is clicked, you must set the BindingNavigator's AddNewItem
' property to 'None'.
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
' Call the DAL's AjaxCustomerAddNew method.
My.Application.DAL.AjaxCustomerAddNew()
End Sub
' This code activates the BindingNavigator's Save button when any column
' of the Customer record is modified.
Private Sub CustomerRecordModified(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
CityTextBox.Validated, LastOrderDateDateTimePicker.Validated, NameTextBox.Validated, _
StateTextBox.Validated, StatusTextBox.Validated, StreetAddress1TextBox.Validated, _
StreetAddress2TextBox.Validated, ZipTextBox.Validated
' If somethings been modified let the user save it.
Me.AjaxCustomerBindingNavigatorSaveItem.Enabled = True
End Sub
' This code is called the BindingNavigator control's Delete button is clicked.
' Note: To prevent the BindingNavigator from automatically deleting the current row
' when the Delete button is clicked, you must set the BindingNavigator's DeleteItem
' property to 'None'.
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
' Cast the AjaxCustomerBindingSource's current object to
' an AjaxDataSet CustomerRow.
Dim currentCustomerRow As DataService.AjaxDataSet.CustomerRow
currentCustomerRow = CType(CType(Me.AjaxCustomerBindingSource.Current, DataRowView).Row, DataService.AjaxDataSet.CustomerRow)
' Verify the user want's to delete the current Customer record.
If MessageBox.Show("Really delete " & currentCustomerRow.Name & "'s customer record?", "Delete Customer Record", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
' Call the DAL's AjaxCustomerDelete method.
My.Application.DAL.AjaxCustomerDelete(currentCustomerRow)
' Enable BindingNavigator's Save button.
Me.AjaxCustomerBindingNavigatorSaveItem.Enabled = True
Else
' Do nothing.
End If
End Sub
' This code is called when the BindingNavigator control's Save button is clicked.
Private Sub AjaxCustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles AjaxCustomerBindingNavigatorSaveItem.Click
Me.AjaxCustomerBindingSource.EndEdit()
' Use the DAL's AjaxCustomerUpdate method to save the Customer records (update the database).
My.Application.DAL.AjaxCustomerUpdate()
' Disable the BindingNavigator control's Save button.
Me.AjaxCustomerBindingNavigatorSaveItem.Enabled = False
End Sub
End Class