Using Combo Box Controls

Top  Previous  Next

About combo box

A combo box is a unique type of control that combines much of the functionality of a list box and an edit control.

A combo box consists of a list and a selection field. The list presents the options a user can select and the selection field displays the current selection. Except in drop-down list boxes, the selection field is an edit control and can be used to enter text not in the list.

Creating the control

Combo box controls are created either through the dialog editor or manually with the CONTROL statement.

Combo box control styles

The following combo box style flags can be specified in the CONTROL statement or by ticking the corresponding check box in the control properties of the dialog editor:

@CTCOMBODROPDOWN

Similar to @CTCOMBOSIMPLE, except that the list box is not displayed unless the user selects an icon next to the edit control.

@CTCOMBODROPLIST

Similar to @CTCOMBODROPDOWN, except that the edit control is replaced by a static text item that displays the current selection in the list box.

@CTCOMBOSIMPLE

Displays the list box at all times. The current selection in the list box is displayed in the edit control.

@CTCOMBOSORT

Automatically sorts strings added to the list box.

@CTCOMBOAUTOHSCROLL

Automatically scrolls the text in an edit control to the right when the user types a character at the end of the line. If this style is not set, only text that fits within the rectangular boundary is allowed.

In addition to the combo box styles, the following window styles can also be specified:

@TABSTOP

Moves the input focus between controls if controls are in a dialog. This style has no effect for controls created in a window.

@GROUP

Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined without the @GROUP style  after the first control belong to the same group. The next control with the @GROUP style starts the next group (that is, one group ends where the next begins)

@HSCROLL

The control has a horizontal scroll bar

@VSCROLL

The control has a vertical scrollbar

Combo box control functions and statements

The following EBASIC functions and statements are used to communicate with the combo box control.

SETSELECTED window | dialog, ID, position

Sets the currently selected item in a list or combo box control. The position value is zero-based and the list or combo box must contain a string at that position.

GETSELECTED (window | dialog, ID)

Returns the zero-based index of the currently selected item in the list box of a combo or single selection list box. Returns -1 if no item is selected. ID must be a list box or combo box.

ISSELECTED (window | dialog, ID, position)

Returns TRUE if the string at position is selected in a multi-selection list or combo box.

GETSTRINGCOUNT (window | dialog, ID)

Returns the number of strings in a list box or combo box control.

GETSTRING (window | dialog, ID, position)

Returns the string at position in a list box or combo box. Position is a zero based index.

ADDSTRING window | dialog, ID, string

Adds a string to a list box or combo box control.   String is added to the end of the list unless sorting is specified in the style of the control.

INSERTSTRING window | dialog, ID, position, text

Inserts a string into a combo or list box control at position.  All other strings are moved down by one position.

DELETESTRING window | dialog, ID, position

Removes a string from a list box or combo box control. Remaining strings are moved up to fill the empty position.

SETHORIZEXTENT window | dialog, ID, width

Sets the horizontal scroll width of a list box or list box portion of a combo box. Control must have been created with the @HSCROLL style. The width is specified in pixels.

SETCONTROLCOLOR window | dialog, ID, fg, bg

Sets the text color and background color of the list box control.

return = CONTROLEXISTS (window | dialog, ID)

Returns 1 if the control with ID exists in the window or dialog.

ENABLECONTROL window | dialog, ID, 0 | 1

Disables or enables the list box control.

SETFOCUS window | dialog, ID

Gives the control the input focus.

SENDMESSAGE window | dialog, msg, wparam, lparam ,ID

Sends a message to the control for advanced functionality.

SHOWWINDOW window, flags, ID

Changes the visibility state of the control. Use @SWHIDE to hide the control and @SWRESTORE to show the control

SETSIZE dialog|window, L, T, W, H ,ID

Changes the size of the control.

Notification messages

An combo box control sends notification messages to the parent window or dialog in the @NOTIFYCODE variable. The ID of the control is found in @CONTROLID.

@CBNDBLCLICK

Indicates the user has double-clicked a list item in a simple combo box.

@CBNERRSPACE

Indicates the combo box cannot allocate enough memory to carry out a request, such as adding a list item.

@CBNKILLFOCUS

Indicates the combo box is about to lose the input focus.

@CBNSETFOCUS

Indicates the combo box has received the input focus.

@CBNDROPDOWN

Indicates the list in a drop-down combo box or drop-down list box is about to open.

@CBNCLOSEUP

Indicates the list in a drop-down combo box or drop-down list box is about to close.

@CBNEDITCHANGE

Indicates the user has changed the text in the edit control of a simple or drop-down combo box. This notification message is sent after the altered text is displayed.

@CBNEDITUPATE

Indicates the user has changed the text in the edit control of a simple or drop-down combo box. This notification message is sent before the altered text is displayed.

@CBNSELCHANGE

Indicates the current selection has changed.

@CBNSELENDOK

Indicates that the selection made drop down list, while it was dropped down, should be accepted.

@CBNSELENDCANCEL

Indicates that the selection made in the drop down list, while it was dropped down, should be ignored.