List box (ListBox) and ComboBox of VCL Components)

Source: Internet
Author: User
Document directory
  • Runtime attributes
ListBox and ComboBox Components

List box and combo box components are also widely used. The list box indicates the standard Windows list box, which provides a user-selected column selection table. If the list box contains more items and cannot be displayed at one time, the scroll bar provides the remainder items in the access list box.

New Term

Some list boxes are the owner-draw table boxes. In the list box, the programmer draws table items from the table box.

If needed, you can customize the list box. Perhaps no one knows that the list box is quite common. The toolbar editor dialog box in Delphi contains two lists, for example:

The box in table 1 on the left is a common list box that lists the possible button groups that can be selected. The list box No. 2 on the right is a self-painted list box, which displays the actual buttons on the toolbar and the text description of the buttons.

A combo box is a special list box. In fact, a combo box is a combination of a list box and an editing control. You can select from the list or enter a value in the edit box. When you select an item from the drop-down list, this item is placed in the editing control. There are five different types of combos. Different types of the combos are determined by the style attribute.

Combo box type
  • Csdropdown -- default value: drop-down combo box. You can select an entry from the list or enter a new item in the editing area. This type of ComboBox can be searched, that is, you can enter one or more characters and press the up or down key to select the entries that best match the user's input characters.
  • Cssimple -- a simple combo box without drop-down arrow. You can use the up and down arrow keys on the keyboard to select an entry, or enter a new entry in the editing area.
  • Csdropdownlist -- drop-down list combo box. In this type of combo box, the edit box is "read-only". You must select an entry, but you can also enter the first letter of the entry to select it. For example, you can enter the P key to select all the entries whose names start with P.
  • Csownerdrawfixed -- the entry is not necessarily a string, it can be a self-drawn image. The ondrawitem event is triggered before each item is displayed. The item height is specified by the itemheight attribute.
  • Csownerdrawvariable -- the entries can be self-drawn images and the height is variable. Two events are triggered before each item is displayed. In the onmeasureitem event response, we can specify the height of the item. Draw each item in the ondrawitem event handle.

Next we have a combotst program, which explains how different types of combox run the program and how it works:

Download the combotst program:Combotst.rar

 

Edit control attributes
Attribute Application Description
Columns ListBox Number of entries in the column. The default value is 0.
Extendedselection ListBox Whether the user can select a series of continuous entries, Shift + Click or Ctrl + Click. The default value is true.
Integralheight ListBox Whether to show only a part of the entry title. If it is set to false, the height of the list box is always an integer multiple of the height of an item, so that the display is not incomplete. The default value is false.
Itemheight Both Specifies the height of the entry title. The default value is 13.
Items Both Contains a list of all strings, tstrings instance
Maxlength ComboBox Specifies the maximum number of characters that a user can enter in the editing area. The default value is 0, indicating no limit.
Multiselect ListBox Can you select multiple options and use them with the extendedselection attribute?
Sorted Both Specifies whether entries in the list box are listed alphabetically
Style Both Specify the style of the list box
Tabwidth ListBox Specify the pixel value of a tab in the list box.
Text ComboBox Used to set or return the text displayed on the ComboBox. For cssimple and csdropdown combox, you can directly modify the text. For other types of combox, text is valid at runtime.Read-only attribute.
Runtime attributes
Attribute Application Description
Itemindex ListBox Returns the number of the selected entries. If multiple entries are selected, the index value of the current entry with focus is returned. If no selected item is returned,-1 is returned, and the first item is 0.
Selcount ListBox Returns the number of items selected at the same time.
Selected ListBox Used to determine whether a specified index number is selected
Sellength ComboBox Returns the number of characters selected by the user in the editing area.
Selstart ComboBox Returns the Starting number of the character selected in the editing area, starting from 0.
Seltext ComboBox Return the text selected in the user editing area.
Topindex ListBox Number of entries displayed at the top of the list box

There are very few ListBox and ComboBox methods for the previously viewed editing components.

  • The clear method is used to clear all items of the control.
  • The itematpos method returns the list items of the specified X and Y coordinates.
  • Select the text in the edit box in ComboBox by using the selectall method.

The most common events used to process a combo box and a list box are onchange and onclick events. Use these events to determine whether or not a specific item is selected in the list box.

Note

Clicking the edit part of the combo box or the drop-down button does not generate an onclick event. Onclick event occurs only when you click in the list box of the combo box.

  • The onchange event is used to check the changes in the edit part of the combo box, just as it is used to edit the control.
  • The ondropdown event is used to check when the drop-down button of the combo box is clicked.
  • Both onmeasureitem and ondrawitem are used for the Self-painting list box and the Self-painting combo box.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.