Ask Reuben

COMBOBOX – Key Strokes

How can user use keystrokes in a COMBOBOX to select an item?

When a COMBOBOX is rendered, the native user interface on desktops and browsers on desktops will normally allow the user to use the keyboard to select a value.  By paying careful attention to the values in the drop-down list, you can facilitate the use of the keyboard and keep the keystrokes the same as they were in the TUI interface.

Take a scenario such as this where the data field is a CHAR(1) and consists of a single alpha-numeric code that is used to indicate something like a group or category.  In the TUI 4gl application this might have been a CHAR(1) variable and a form field 1 character wide in the .per, and the COMMENT attribute you have set to something like…

COMMENT = "Press A for Group A, B for Group B, C for Group C".

The temptation when transforming this application for a GUI interface was to use COMBOBOX and set the ITEMS to be something like …

ITEMS = (("A", "Group A),("B", "Group B"), ("C", "Group C"))

The problem with this is that the user can no longer press A,B,C to select the required group.  With a little bit of thought, a better value for ITEMS is

ITEMS = (("A", "A-Group A),("B", "B-Group B"), ("C", "C-Group C"))

Now the user will see “A-Group A”, “B-Group B”, “C-Group C” etc instead of “Group A”, ‘Group B”, “Group C”.  The typical native widget will then allow the user to press A, B, or C and the desired row will be selected from the drop-down.

Similarly if using ui.ComboBox.addItem method as part of an INITIALIZER my normal pattern is something like …

CALL cb.addItem(value, SFMT("%1-%2", value, desc))

… to ensure that the first part of the list value matches the natural keyboard entry.

There is also an interesting presentation style named “autoSelectionStart” that is associated with COMBOBOX.  This says that when you press a key in a ComboBox, does it look for the first item beginning with that letter from the “current” position in the list, or from the “first” position in the list.  A value of “first” more closely matches the TUI keyboard experience.  This is useful in scenarios where the list is unordered, or ordered in the list of more frequently used values at the top.  If the current value in the list is the second item in the list, pressing the key associated with the first item in the list should select that first item in the list that begins with that key, not the next entry in the list beginning with the key.  This style attribute is only available with GDC as I don’t think Browsers allow us to override this behaviour unfortunately.

So take care with the characters you use in the description part of the list, by including the keyboard accelerator at the beginning of the description you can facilitate keyboard entry with the ComboBox.