Results 1 to 8 of 8

Thread: Combo Box

  1. #1

    Thread Starter
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241
    Hi

    Just a quick question, is there any way of stopping a user typing text into a combo box, i.e. so they can only select what appears in the drop down list? I have tried using the lock propety but it does not let you select anything from the list or type anthing in.

    Any takers?

    Cheers

    Geoff

  2. #2
    Member
    Join Date
    Jan 1999
    Location
    Longmont,CO
    Posts
    53

    Thumbs up

    You need to handle the combo box's keypress and keydown events. You can then set the keyascii and keydown values to 0 and vbnull, respectively. Let me know if you need an example.

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Or better yet, just change the Style property of the Combobox to 2 (Dropdown List).

  4. #4

    Thread Starter
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241

    Smile

    Thanks

    Just the ticket!

    Geoff

  5. #5
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241

    Cool

    Some code examples would be nice on how to set it to null. I did a routine on keypress and there still is the possiblity of saving it with one character if you do it right; or is that wrong? by the user?

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    Sure. All you have to do is to set ListIndex property to -1.

    Code:
    Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyDelete Then
            Combo1.ListIndex = -1
        End If
    End Sub
    Regards,

  7. #7
    New Member
    Join Date
    Jun 2000
    Posts
    8

    Wink Combo

    About how not to allow the user to input anything in a combobox

    Private Sub cboBox_Change()
    cboBox.Text = "" 'or whatever text
    End Sub

  8. #8
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    No, use Combobox1_KeyPress and Combobox1_KeyUp events to do that:
    Code:
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
        KeyAscii = 0
    End Sub
    
    Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
        KeyCode = 0
    End Sub

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