Results 1 to 7 of 7

Thread: [RESOLVED] Events triggered when typing in ComboBox dropdown list

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    789

    Resolved [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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,254

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    789

    Re: Events triggered when typing in ComboBox dropdown list

    That's brilliant. Thank you so much.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    789

    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    789

    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.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,254

    Re: [RESOLVED] Events triggered when typing in ComboBox dropdown list

    Quote Originally Posted by sgrya1 View Post
    I worked it out. I selected another control before loading the form, removing it's focus which stopped SelectedIndexChanged from being triggered again.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,634

    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
  •  



Click Here to Expand Forum to Full Width