Public Class form
Private _LocationID As Integer
Private FormIsLoading As Boolean
Private Sub frmLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Private Sub frmLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Dos_trackDataSet.depot' table. You can move, or remove it, as needed.
Me.DispatchTableAdapter.Fill(Me.Dos_trackDataSet.dispatch)
'TODO: This line of code loads data into the 'Dos_trackDataSet.freight' table. You can move, or remove it, as needed.
Me.FreightTableAdapter.FillFreightInfo(Me.Dos_trackDataSet.freight)
'TODO: This line of code loads data into the 'Dos_trackDataSet.depot' table. You can move, or remove it, as needed.
Me.LocationsTableAdapter.FillbySiteName(Me.Dos_trackDataSet.locations)
Me.txtLocation.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "site")
Me.txtAAC.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "aac")
Me.txtPhone.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "telephone_nbr")
Me.txtFax.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "fax_nbr")
Me.cboFreight.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "freight_refnbr")
Me.cboDispatcher.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "dispatch_refnbr")
Me.txtEmail.DataBindings.Add("text", frmEditDel.LocationsBindingSource, "Email")
Me.cboDepot.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.LocationsBindingSource, "depot_refnbr", True))
''TODO: This line of code loads data into the 'Dos_trackDataSet.freight' table. You can move, or remove it, as needed.
Me.FreightTableAdapter.FillFreightInfo(Me.Dos_trackDataSet.freight)
'Me.FreightTableAdapter.FillFreightInfo(frmEditDel.Dos_trackDataSet.freight)
'TODO: This line of code loads data into the 'Dos_trackDataSet.dispatch' table. You can move, or remove it, as needed.
Me.DispatchTableAdapter.Fill(Me.Dos_trackDataSet.dispatch)
'Find out if the form is loading, if yes, ignore "SelectedIndexChanged"
'event of cboDepot
FormIsLoading = True
'TODO: This line of code loads data into the 'Dos_trackDataSet.locations' table. You can move, or remove it, as needed.
Me.DepotTableAdapter.FillByMatchDepotRefNbr(Me.Dos_trackDataSet.depot)
'Set combobox to datasources
Me.cboDepot.ValueMember = "depot_refnbr"
Me.cboDepot.DisplayMember = "depot_name"
Me.cboDepot.DataSource = Me.DepotBindingSource
'Get all locations
Me.LocationsTableAdapter.FillbySiteName(Dos_trackDataSet.locations)
'Bind locations to combobox's "SelectedValue"
Me.cboDepot.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.LocationsBindingSource, "depot_refnbr", True))
'Find the Location from the previous form
Dim Position As Integer = Me.LocationsBindingSource.Find("site_refnbr", _LocationID)
If Position <> -1 Then
Me.LocationsBindingSource.Position = Position
End If
'Allow the combobox to do its work again
FormIsLoading = False
End Sub
'Constructor you will see in frmEditDel we will call frmLocation with a parameter
Public Sub New(ByVal site_refnbr As Integer)
_LocationID = site_refnbr
'Call required by Windows Form Designer
InitializeComponent()
Me.cboDepot.Text = CStr(site_refnbr)
End Sub
Private Sub cboDepot_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDepot.SelectedIndexChanged
'If the form is not loading and the user changes the depot, we want to save it
If FormIsLoading = False Then
Try
'First validate all controls
Me.Validate()
'Tell bindingsource to go to end edit mode
Me.LocationsBindingSource.EndEdit()
'Update the locations
Me.LocationsTableAdapter.FillByUpdate(Me.Dos_trackDataSet.locations)
Catch ex As Exception
MsgBox("Update failed")
End Try
End If
End Sub