Combobox and Restrict Entry

  1. 4 years ago

    Not sure I can do this, if so I can't see how.

    I have a combobox with an associated list. What I want to do is ensure that the user can only select / enter a value from the list, restricting what he can type into the edit box of the list.

    Can anyone tell me how I do this?

    Thanks

    Phil

  2. Bob K

    25 Apr 2015 Pre-Release Testers, Xojo Pro Kansas City

    Just off the top of my head here:

    In the KeyDown event you can see what the current text is and if it matches anything in the list let them keep typing. As soon as there's no match return true which I think will show the beep.

    If you want autocomplete you could set the text when there is one and only one match from the list.

  3. Markus W

    25 Apr 2015 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    @Phil C I have a combobox with an associated list. What I want to do is ensure that the user can only select / enter a value from the list, restricting what he can type into the edit box of the list.

    that's what a PopupMenu is for.

    ComboBox is for when a user can add new entries that are not in the list.

  4. Peter T

    25 Apr 2015 Pre-Release Testers, Xojo Pro Oakland, CA USA

    @Markus W that's what a PopupMenu is for.

    How then does one create a PopupMenu with autocomplete?

  5. Markus W

    25 Apr 2015 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    @Peter T How then does one create a PopupMenu with autocomplete?

    That question makes absolutely no sense.

  6. Michel B

    25 Apr 2015 Pre-Release Testers RubberViews.com

    @Peter T How then does one create a PopupMenu with autocomplete?

    I believe there are two approaches : "à la Xojo" and "à la Google".

    A la Xojo where the first possible termination appears as grey right after the caret is possible with a canvas laid over the TextField showing the grey text.

    -image-

    All you need is this kind of code in the paint event displayed if the entered text matches the first part of the probable complete :

    Sub Paint(g As Graphics, areas() As REALbasic.Rect)
      g.ForeColor = &cB3B3B300
      g.textsize = 0
      g.textfont = "System"
      g.DrawString("tsointsoin", 48,16)
    End Sub

    Now the tricky part is to use TextWidth to see where the entered text ends, so you can display the grey proposition. In the example above I did it "hard coded" just for demo purposes.

    The à la Google way requires using a listbox underneath to display the different propositions, essentially the way the drop down menu would. But since I found no way to drop the list by code, that is the way I would do it.

    That said, I agree with Markus. It seems a bit futile not to use simply a PopupMenu.

  7. For a user interface the Combobox works best with a large number of items as the user can start to type in and use auto complete to find what they want. With a PopupMenu a long list makes the UI not so easy. Agree for a shortlist (like a menu) then this control works fine.

    Phil

  8. Michel B

    26 Apr 2015 Pre-Release Testers RubberViews.com

    @Phil C For a user interface the Combobox works best with a large number of items as the user can start to type in and use auto complete to find what they want. With a PopupMenu a long list makes the UI not so easy. Agree for a shortlist (like a menu) then this control works fine.

    Phil

    I see. Sort of what I called the Google way. In that case, you may not even want a Combobox. As far as I know, there is no way to have the menu drop to present available selections.

    You could instead use a simple textfield, and show a ListBox, or a ContextualMenu when the selection has become short enough to pick an item.

    The tip I posted still remains valid to display the first possibility, though.

  9. Norman P

    26 Apr 2015 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    You could use the keydown to test if the existing text + the new key would make for the beginning of one of the items in the list.
    if it does allow the key
    if not reject it

  10. Peter T

    26 Apr 2015 Pre-Release Testers, Xojo Pro Oakland, CA USA

    @Markus W That question makes absolutely no sense.

    Actually, it makes perfect sense - to me at least :P

    What the OP, and others including me, are wanting is a control which allows the user to enter keystrokes and take advantage of autocomplete (à la ComboBox) but without the user being able to enter anything that's not already in the list.

    Your response

    that's what a PopupMenu is for.

    is what' seems nonsensical to me...

  11. Markus W

    26 Apr 2015 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    "A PopupMenu with autocomplete" is non-sensical.

    A ComboBox with autocomplete is possible.

    A TextField with autocomplete and a custom menu control is possible.

  12. Markus W

    26 Apr 2015 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    Btw is ComboBox.Autocomplete not working?

    http://docs.xojo.com/index.php/ComboBox.AutoComplete

  13. 2 years ago

    @Markus W Btw is ComboBox.Autocomplete not working?

    http://docs.xojo.com/index.php/ComboBox.AutoComplete

    This works, but does not restrict the user from filling in data that is not in the list.

  14. Markus W

    13 Jan 2017 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...

    @Peter T Actually, it makes perfect sense - to me at least :P

    What the OP, and others including me, are wanting is a control which allows the user to enter keystrokes and take advantage of autocomplete (à la ComboBox) but without the user being able to enter anything that's not already in the list.

    Your response is what' seems nonsensical to me...

    It still seems a bit nonsense to me, and it will peeve users off (who are used to popup menus giving a limited choice and ComboBox allowing entry of new data too), but just use a ComboBox and on loosing focus check that the entry is indeed in the list.

  15. Markus W

    13 Jan 2017 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...
    Edited 2 years ago

    @Mathias M This works, but does not restrict the user from filling in data that is not in the list.

    Nothing will (be it a ComboBox or a TextField). That's up to you. You will always need to check the entry against your list.

    Assume you only have two entries with A: Anna and Anne

    What stops the user to just type An and then click somewhere else? What do you do now?

  16. @Markus W Nothing will (be it a ComboBox or a TextField). That's up to you. You will always need to check the entry against your list.

    Assume you only have two entries with A: Anna and Anne

    What stops the user to just type An and then click somewhere else? What do you do now?

    Handle it with KeyDown event. I'm a subclass right now. But I have to go now. Will work on it this evening. I will share it with anyone who wants it.

  17. Markus W

    13 Jan 2017 Pre-Release Testers, Xojo Pro #JeSuisHuman Germany, Heidelb...
    Edited 2 years ago

    @Mathias M Handle it with KeyDown event

    I doubt that will work. You'll see.

  18. Tim P

    13 Jan 2017 Pre-Release Testers feedback://46303

    (I know this thread is old, but it got bumped - I'm just offering User Experience tips)

    @Peter T What the OP, and others including me, are wanting is a control which allows the user to enter keystrokes and take advantage of autocomplete (à la ComboBox) but without the user being able to enter anything that's not already in the list.

    When a user pops open a PopupMenu they can start typing to select an item.

    @Mathias M This works, but does not restrict the user from filling in data that is not in the list.

    That is not the point of a ComboBox. Use a PopupMenu.

  19. Tim P

    13 Jan 2017 Pre-Release Testers feedback://46303
    Edited 2 years ago

    Overall (not directed at anybody in particular)
    The point of a ComboBox is to offer a combination of TextField and PopupMenu. It allows you as a developer to provide a list of common examples that could save the user time, but allows them to fill in a value you might not have accounted for. By not allowing them to enter their own value, you're tossing out the purpose of the control.

    For example, you might see a ComboBox on a form for an Operating System field. It could start with Mac and Windows, but would allow a Linux user to type in their system. This is a super simplified example. We of course would know to add Linux to the list, and it may seem trivial to select from 1 of 3 options - but you have other UI issues if your PopupMenu is so long it can't be navigated.

  20. Newer ›

or Sign Up to reply!