Answer: – A combo box is a combination of list box and edit control. A simple combo box is just a list box with an edit control at the top. You can select from the list or type. A combo box with style “drop down” is the same, but the list box doesn’t show up until you click the drop-down glyph. You can dropdown and select or just type in the edit control. A combo box with dropdown list style is similar, but you can only from the list presented. You can’t type in what you want in the edit control. Basically, a combo box (non-simple style) takes up a lot less screen real-estate than a full-on list box.

List box control: – A list box control presents a set of choices that are displays vertically in a single column. If the number of item exceed the value that can be display, scroll bars will automatically appear on the control. These scroll bars can be scroll up and down or left to right through the list. When user click on any choice, it is automatically added in the text box of list box control. List box control contains a triangle sign at the right side of that control.

To add items at design time, click list option in the property box and them add the items. Press CTRL + Enter key after adding each item. When all the items are entered in the list property. Press only enter key to close list property and return back.

Combo box control: – The combo box control works similar to list box control. They both display a list of item to the user. They both have list, list count, list index and shorted properties. They both have add item, clear and remove item methods.

In addition, a combo box also has a rectangular area that function like a text box. The user may either select an item from the combo boxes list or type text into the combo boxes text input area. Like a text box, the combo box has a text property. If the user type text into the combo box, the text is stored in the text property. Also, when the user selects an item from the combo boxes list, the item is copied to the text property.

Combo box control provide three different style and its effects will be seeing at the run time. The combo box styles are style-0, style-1 and style-2.

  • (i) Style-0: – This is the default setting for the combo box style property. At the run time, a drop down combo box appears. This style of combo box behaves like either a text box or a list box. The user may either type text into the box or click the down arrow.
  • (ii) Style-1: – With this style of combo box, the list of items does not drop down but is always display. User can select by clicking on it.
  • (iii) Style-2: – With this style, user may not type text directly into the combo box but it can be select from the list. It provides drop down arrow key.

Some properties of list box: – There are number of properties and method used with list box control during the run time. These properties actively used in code window. Properties and method of list box control are as follows –

ListCount properties: – We can use the list count properties to determine the number of item that are stared in the list properties. When there are no items in the list properties, list count will hold value zero. Syntax of the ListCount properties is –

                <Variable Name>.ListCount

ListIndex properties: – When the user selects an item in a list box, that item’s index is stored in the list index properties. If no item is selected, list index is set to -1. We can use the list index properties to retrieve the selected item from the list properties. Syntax of the ListIndex properties is –

                <Variable Name>.ListIndex

Sorted properties: – We can use the list boxes sorted property to cause the items in the list properties to be display in alphabetical order. The properties, which is Boolean, is set to false by default. When set to false, the items are displayed in the ordered they were entered or inserted. When set to true, items are alphabetically sorted. Syntax of the sorted properties is –

                <Variable Name>.Sorted=True/False

AddItem method: – To store items in the list properties at run time, we must right code that uses the list boxes add item method. Syntax of the add item method is –

                <Variable Name>.AddItem <Item> [, Item]

Here, variable name is the name of list box control. Item is a string that is to be added to the list property. Index is an optional integer argument that specifies the position where item is to place in the list properties. If it is not specified, items automatically appended at the end of the list box entry.

Clear method: – The clear method erases all the items in the list properties. If this method used at run time, all items are removed from the list box control.  Syntax of the clear method is –

                <Variable Name>.Clear

Remove item: – This method is used to remove particular item from the list box. An index number is needed with this method for removing the item. Syntax of the remove item method is –

                <Variable Name>.RemoveItem <Index>
Advertisements