Results 1 to 3 of 3

Thread: click event in combo when value is changed

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Thumbs down

    Hello,

    I've got a form with a few combo boxes on it. The style of the boxes is set to "2 - Dropdown List"

    in some other code i set the value of the comboboxes to something: eg

    combo1.text = "hi there"

    but when i do this it fires off the "click" event of the combo box (which does a whole heap of other processing that i don't want to do unless the user itself clicks the combo box - not when i change it programatically).

    Is there a way to avoid the click event firing when the text of the combo box is set from within the code. I still want it to happen when the user actually clicks the combo.

    Thanks - it's a bit important

    if i'm not being clear then ask me - i'll explain better.

    Mark

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    Try this primitive approach until I find something more professional:
    Code:
    Option Explicit
    Dim blClick As Boolean '//boolean used to determine if the
    '//user click the combo or if the text changed with code
    
    Private Sub Combo1_Click()
        If blClick = False Then '//user chose to click the combo himself/herself
            '//do whatever you want when the user clicks the combobox
            MsgBox "Combo has been clicked"
        End If
        
        blClick = False '//reset the boolean
    End Sub
    
    Private Sub Command1_Click()
        blClick = True '//text of the combo will be changed with code
        Combo1.Text = "Welcomes" '//change the combo's text
    End Sub
    
    Private Sub Form_Load()
        '//just to populate the combo
        With Combo1
            .AddItem "John"
            .AddItem "Welcomes"
            .AddItem "To"
            .AddItem "VB"
            .AddItem "World"
        End With
    End Sub
    I hope you can follow what I did.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Smile

    Thanks QWERTY,

    it may be that i have to take an approach like that - although it is not the nicest way (like you said).

    i have discovered though if the combobox's style property is set to "0 - Dropdown Combo" the problem doesn't exist - ie the click event isn't fired - however if i use this style then the user can type whatever they want in the combobox which opens another can of worms.


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