-
Sep 11th, 2021, 03:20 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Events triggered when typing in ComboBox dropdown list
Hi,
I need code to be triggered by selecting a ComboBox entry with the mouse, or by typing the entry in.
When typing it in, the SelectedIndexChanged event gets triggered multiple times, which is a problem so I added a timer to bypass it.
I can't have MyCODE running more than once.
For some reason both SelectedIndexChanged and ComboBoxTimer_Tick are executing MyCODE.
Can anyone suggest a fix?
Code:
Private Sub ComboBox_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles cboShape.KeyPress
Timer_ComboBox.Enabled = False
Timer_ComboBox.Enabled = True
End Sub
Private Sub ComboBoxTimer_Tick(ByVal sender As System.Object, ByVal e As EventArgs)
Timer_ComboBox.Enabled = False
Timer_ComboBox.Dispose()
MyCODE
End Sub
Private Sub cboShape_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cboShape.SelectedIndexChanged
If Timer_ComboBox.Enabled = False Then
MyCODE
End If
End Sub
-
Sep 11th, 2021, 03:26 PM
#2
Re: Events triggered when typing in ComboBox dropdown list
This should work. I'm assuming the timer is called ComboBoxTimer
Code:
Private Sub cboShape_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cboShape.SelectedIndexChanged
If ComboBoxTimer.Enabled = False Then
ComboBoxTimer.Enabled = True
End If
End Sub
Private Sub ComboBoxTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBoxTimer.Tick
ComboBoxTimer.Enabled = false
MyCODE
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 11th, 2021, 03:34 PM
#3
Thread Starter
Fanatic Member
Re: Events triggered when typing in ComboBox dropdown list
That's brilliant. Thank you so much.
-
Sep 11th, 2021, 03:52 PM
#4
Thread Starter
Fanatic Member
Re: [RESOLVED] Events triggered when typing in ComboBox dropdown list
Oh no, it's not quite resolved. Timer_Tick loads a modal form, which for some reason triggers SelectedIndexChanged, restarting the timer and causing it to tick again.
Is there anything I could do to prevent this?
Code:
Private Sub ComboBoxTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBoxTimer.Tick
ComboBoxTimer.Enabled = false
FormWait.ShowInTaskbar = False
Application.ShowModalDialog(Application.MainWindow.Handle, FormWait, False)
End Sub
-
Sep 11th, 2021, 05:21 PM
#5
Thread Starter
Fanatic Member
Re: [RESOLVED] Events triggered when typing in ComboBox dropdown list
I worked it out. I selected another control before loading the form, removing it's focus which stopped SelectedIndexChanged from being triggered again.
-
Sep 11th, 2021, 05:28 PM
#6
Re: [RESOLVED] Events triggered when typing in ComboBox dropdown list
Originally Posted by sgrya1
I worked it out. I selected another control before loading the form, removing it's focus which stopped SelectedIndexChanged from being triggered again.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 11th, 2021, 11:03 PM
#7
Re: [RESOLVED] Events triggered when typing in ComboBox dropdown list
Perhaps you should have been handling SelectionChangeCommitted rather than SelectedIndexChanged.
Also, what are you actually trying to achieve? I strongly suspect that there should be no Timer involved but it's hard to say because this is one of those questions where you have described how you're trying to achieve something but not what that thing is that you're trying to achieve.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|