Programming C++Builder How to Use TListBox, TCheckListBox, and TComboBox in C Builder?
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/ on line 149

List controls List

Lists present the user with a collection of items to select from. Several components display lists:

Use this component: To display:
TListBox A list of text strings
TCheckListBox A list with a check box in front of each item
TComboBox An edit box with a scrollable drop-down list
TTreeView A hierarchical list
TListView A list of (draggable) items with optional icons, columns, and headings
TIconView (CLX only) A list of items or data in rows and columns displayed as either small or large icons
TDateTimePicker A list box for entering dates or times (VCL only)
TMonthCalendar A calendar for selecting dates (VCL only)

Use the nonvisual TStringList and TImageList components to manage sets of strings and images. For more information about string lists, see Working with Strings in C++Builder.

How to Use List boxes and check-list boxes?

List boxes (TListBox) and check-list boxes display lists from which users can select items.

  1. Items uses a TStrings object to fill the control with values.
  2. ItemIndex indicates which item in the list is selected.
  3. MultiSelect specifies whether a user can select more than one item at a time.
  4. Sorted determines whether the list is arranged alphabetically.
  5. Columns specifies the number of columns in the list control.
  6. IntegralHeight specifies whether the list box shows only entries that fit completely in the vertical space (VCL only).
  7. ItemHeight specifies the height of each item in pixels. The Style property can cause ItemHeight to be ignored.
  8. The Style property determines how a list control displays its items. By default, items are displayed as strings. By changing the value of Style, you can create owner-draw list boxes that display items graphically or in varying heights. For information on owner-draw controls, see How to Adding Graphics to Controls in C++Builder .

To create a simple list box,

  1. Within your project, drop a list box component from the Component palette onto a form.
  2. Size the list box and set its alignment as needed.
  3. Double-click the right side of the Items property or choose the ellipsis button to display the String List Editor.
  4. Use the editor to enter free form text arranged in lines for the contents of the list box.
  5. Then choose OK.

To let users select multiple items in the list box, you can use the ExtendedSelect and MultiSelect properties.

How to use Combo boxes?

A combo box (TComboBox) combines an edit box with a scrollable list. When users enter data into the control--by typing or selecting from the list--the value of the Text property changes. If AutoComplete is enabled, the application looks for and displays the closest match in the list as the user types the data.

Three types of combo boxes are: standard, drop-down (the default), and drop-down list.

  1. Use the Style property to select the type of combo box you need.
  2. Use csDropDown if you want an edit box with a drop-down list. Use csDropDownList to make the edit box read-only (forcing users to choose from the list). Set the DropDownCount property to change the number of items displayed in the list.
  3. Use csSimple to create a combo box with a fixed list that does not close. Be sure to resize the combo box so that the list items are displayed.
  4. Use csOwnerDrawFixed or csOwnerDrawVariable to create owner-draw combo boxes that display items graphically or in varying heights. For information on owner-draw controls, see How to Adding Graphics to Controls in C++Builder .

At runtime, CLX combo boxes work differently than VCL combo boxes. In CLX (but not in the VCL combo box), you can add a item to a drop down by entering text and pressing Enter in the edit field of a combo box. You can turn this feature off by setting InsertMode to ciNone. It is also possible to add empty (no string) items to the list in the combo box. Also, if you keep pressing the down arrow key, it does not stop at the last item of the combo box list. It cycles around to the top again.

Add comment

Security code

Programming - C++Builder