Results 1 to 6 of 6

Thread: ComboBox problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Norway
    Posts
    11

    Post

    How can i make my combobox not editable ?
    I only want the users to be able to pick from the list, not edit the items in it. I tried to lock it, but then i couldnt choose any item at all..
    thnx for any help

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Hi, dialafc.
    Set Style property to 2-Dropdown List.

    Larisa

  3. #3
    New Member
    Join Date
    Jan 2000
    Location
    Stellenbosch, South Africa
    Posts
    12

    Post

    Hi, setting the property causes you to be unable to add items to the drop-down box
    programmatically.

    I use:

    MsgBox "No Typing allowed here. Please select only!"
    Combo43.Text = ""

    regards,
    AJM

  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    As far as I know Abie is wrong since you can always add items to the list programmatically (even it is a drop-down listbox only). What he may mean is it is impossible to set the .Text property of the combobox to something that isn't in the dropdown list..



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  5. #5
    New Member
    Join Date
    Jan 2000
    Location
    Stellenbosch, South Africa
    Posts
    12

    Post

    Hi, I forgot to tell.

    Put this on the KeyPress function


    Private Sub Combo43_KeyPress(KeyAscii As Integer)

    MsgBox "No Typing allowed here. Please select only!"
    Combo43.Text = ""

    End Sub

    Regards
    AJM

  6. #6
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    The problem with that is really devious users (and most of them are) can copy text from somewhere and (providing they use the popup menu on the right mouse button) paste it into your combobox - Abie's Keypress code would never get run.

    Use a combobox, style set to 2-dropdown list. Now users can only select text in the dropdown - if you want to clear the box, use

    Combo1.ListIndex=-1

    in code. If you must you could always attach that to a keydown event (eg vbKeyDelete)

    eg;

    Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDelete Then Combo1.ListIndex = -1
    End Sub

    Now, if someone presses DELETE when the combobox has the focus it will be cleared.

    That ought to do it.



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



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