SelectedIndexChanged

jfackler

Junior Contributor
Joined
Mar 15, 2003
Messages
393
Location
Cincinnati, Ohio
Anyone know how I can keep an event from firing on the page load only?
The combobox cmbPTOweekone in the third box of code is bound to a dataset:
Visual Basic:
lblPTOAnnual.DataBindings.Add("text", dataset1, "Employees.BeginningPTO")
        lblPTORemain.DataBindings.Add("Text", dataset1, "Employees.RemainingPTO")
        cmbPTOweekone.DataBindings.Add("SelectedItem", dataset1, "Employees.WeekOnePTO")
        cmbPTOweektwo.DataBindings.Add("SelectedItem", dataset1, "Employees.WeekTwoPTO")
        cmbHolidayHoursOne.DataBindings.Add("SelectedItem", dataset1, "Employees.WeekOneHoliday")
The binding context is passed in as a public variable from a dialog box requesting the selection of an employyee.
Visual Basic:
  Me.BindingContext(dataset1, "Employees").Position = intSelectedEmployee
Everything works fine except when I change the binding context and the form is reinstantiated, the cmbPTOweekone_SelectedIndexChanged event is fired and the msgbox is fired if the condition is met. The value it's comparing however, is that from the previous binding context.
Visual Basic:
Private Sub cmbPTOweekone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPTOweekone.SelectedIndexChanged
        If cmbPTOweektwo.Text = "" Then
            cmbPTOweektwo.SelectedIndex = 0
        End If
        If CInt(cmbPTOweekone.Text) > (CInt(dataset1.Tables("Employees").Rows(intSelectedEmployee).Item("RemainingPTO")) - CInt(cmbPTOweektwo.Text)) Then
            cmbPTOweekone.SelectedIndex = 0
            MessageBox.Show("You have taken more PTO than remains in your banked Paid Time Off.  Please correct your entry.", "PTO Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End If
        fillthetotals()
    End Sub
It seems to be a timing issue. The comboboxes bind correctly and the msgbox only fires when the condition is met.

Thanks,
Jon
 
Okay,
Like frequently happens, trying to explain the problem to someone else helps clarify the answer.

I moved the binding context prior to the databindings....problem solved.
However, the question remains, can I (or should I ever need to if my code is good) keep an event from firing once i.e. only after it is fired twice, or n times?
 
Back
Top