0

I have some logic being handled in the Validated event on a combobox, but would like it to trigger as soon as a selection is made. I can handle the SelectedIndexChanged event separately in order to fire the event, but I'm not sure how to invoke it.

Private Sub ComboSelectedIndexChanged(sender As System.Object, e As System.EventArgs) _
    Handles ComboBox1.SelectedIndexChanged
    'Fire Validated Event
End Sub

Private Sub ComboValidated(sender As System.Object, e As System.EventArgs) _
    Handles ComboBox1.Validated
    'Do Something Here
End Sub

I'd rather not call into the method handling the validated event directly,

ComboValidated(Nothing, Nothing)

as it's not precisely what I'm trying to do with the code and it will run a second time when in fact the validated event actually does fire upon losing focus.

What code can I execute to fire the validated event (either by fire the event directly or by causing the control to lose focus)?

4

2 回答 2

1

你为什么不把它变成 Sub ..

Private Sub ComboValidated(sender As System.Object, e As System.EventArgs) _
    Handles ComboBox1.Validated

    InCBValidated()

End Sub

Sub InCBValidated()

    'Do Something Here

End Sub

所以你只要打电话InCBValidated()

于 2013-06-05T17:47:44.057 回答
0

我通过使控件失去焦点来解决这个问题,然后触发所有必要的事件。该控件恰好在一个组合框中,因此删除焦点的最简单方法就是赋予该控件焦点,以便仍然选择页面上的相同位置

Private Sub ComboSelectedIndexChanged(sender As System.Object, e As System.EventArgs) _
    Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.Focused Then GroupBox1.Focus()
End Sub
于 2013-06-05T18:58:50.623 回答