Difference between revisions of "DComboBox"

From Dabo Wiki
Jump to: navigation, search
(Created page with "This control allows the user to select one item from a pre-set list of items, or optionally type in an item that it not in the list. It is similar to dDropdownList, except...")
(No difference)

Latest revision as of 16:04, 12 May 2020

This control allows the user to select one item from a pre-set list of items, or optionally type in an item that it not in the list. It is similar to dDropdownList, except that this control contains an editable textbox for user-entered information.

It normally appears as a single line displaying the selected item, along with an arrow button which the user clicks to "drop down" the full list. When a selection is made from that list, the list disappears, leaving the single-line control. Because its full list isn't displayed until the user selects it, it is ideal for presenting a selection without taking up a lot of area on the screen.

Some of the more useful properties:

  • AppendOnEnter - (bool): When this is True, any item the user types into the textbox is automatically appended to the list of Choices when they press the Enter key. There are two hook methods: beforeAppendOnEnter() and afterAppendOnEnter(). These get automatically called before and after the new item is appended to the Choices list. The beforeAppendOnEnter() method gives you a chance to manipulate the user-entered value, and optionally prohibit the addition by returning False from the method. The afterAppendOnEnter() method gives you a chance to do post-processing.
  • Choices - (list): This determines the options available for the control.
  • Keys - (dict / list / tuple): Value that is associated with the Choices. Many times you want to present the user with a list of choices that mean something to them, but internally in your program, you really need the ID or primary key or some other identifying value that is associated with the choice that the user made. The easiest way to set up the Keys property is to make it a 1:1 list of values that correspond position-wise to the Choices list. This way, when the user selects, say, the third choice in the list, KeyValue will return the third value in the Keys list.
  • StringValue - (str): Returns the text displayed by the control for the selected item.
  • PositionValue - (int): Returns the position of the selected item in the list of available Choices.
  • KeyValue - (varies): Returns the value in Keys that corresponds to the selected item.
  • UserValue - (str): Represents the text typed in by the user. UserValue can differ from StringValue, which would mean that the user has typed in arbitrary text. Unlike StringValue, PositionValue, and KeyValue, setting UserValue does not change the currently selected item in the list portion of dComboBox.
  • ValueMode (str): Can be one of String, Position, or Key. Determines the result returned by accessing the Value property: either StringValue, PositionValue or KeyValue. You can always refer to any of those different value types, but when you know which value your program will be needing, you can set ValueMode, and afterwards just have the normal Value binding work correctly.

See the Dabo Class Documentation for an exhaustive documentation of this control's Properties, Events and Methods. (Note that this documentation is no longer live, but it's still available via the Internet Archive).