puccij
05-18-2004, 07:19 AM
I have a combobox on a form. When the selected value changes I want to repopulate a number of iother values on the form, but first I want to check to see if the user wants to save changes.
The problem is that this often will require that the code cancel the click event which as far as I can tell is not possible. If you use the vailidating event the code only fires when the combo loses focus.
The only work around I have seen posted is to capture the old selected index and reset the value if a "cancel" event is needed.
I have another suggestion that seems fairly obvious. I am simply putting the cancel code in the validating event, but also adding code to the click event that selects the next c ontrol on my form. This has the effect of instantly triggerring the valding event.
It ain't pretty but it's getting the job done.
Private Sub ComboChange(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating
If CheckDataSave then e.Cancel = true
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged
nextcontrol.Select
End Sub
The problem is that this often will require that the code cancel the click event which as far as I can tell is not possible. If you use the vailidating event the code only fires when the combo loses focus.
The only work around I have seen posted is to capture the old selected index and reset the value if a "cancel" event is needed.
I have another suggestion that seems fairly obvious. I am simply putting the cancel code in the validating event, but also adding code to the click event that selects the next c ontrol on my form. This has the effect of instantly triggerring the valding event.
It ain't pretty but it's getting the job done.
Private Sub ComboChange(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating
If CheckDataSave then e.Cancel = true
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged
nextcontrol.Select
End Sub