Imports System.Windows.Forms

Public Class StudentForm
    Private iDBinding As Binding
    Private givenNameBinding As Binding
    Private familyNameBinding As Binding
    Private dobBinding As Binding
    Private cityBinding As Binding

    Private Sub saveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveButton.Click
        MainForm.StudentBindingSource.EndEdit()
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Hide()
    End Sub

    Private Sub cancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelButton1.Click, cancelButton1.Click
        MainForm.StudentBindingSource.CancelEdit()
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Hide()
    End Sub

    Private Sub setBindings()
        iDBinding = New Binding("Text", MainForm.StudentBindingSource, "ID")
        givenNameBinding = New Binding("Text", MainForm.StudentBindingSource, "GivenName")
        familyNameBinding = New Binding("Text", MainForm.StudentBindingSource, "FamilyName")
        dobBinding = New Binding("Text", MainForm.StudentBindingSource, "DateOfBirth", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "d")
        cityBinding = New Binding("Text", MainForm.StudentBindingSource, "City")
        idTextBox.DataBindings.Add(iDBinding)
        givenNameTextBox.DataBindings.Add(givenNameBinding)
        familyNameTextBox.DataBindings.Add(familyNameBinding)
        dobTextBox.DataBindings.Add(dobBinding)
        cityTextBox.DataBindings.Add(cityBinding)
    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        setBindings()
    End Sub

End Class
