Difference between revisions of "ComboBox Control in VB6"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
m
m (Multi-Columns Combo Box)
Line 47: Line 47:
 
  cboEData(4).AddItem rs1!PLValue
 
  cboEData(4).AddItem rs1!PLValue
 
  cboEData(4).List(0, 1) = rs1!PLID
 
  cboEData(4).List(0, 1) = rs1!PLID
 +
 +
cboBoxName.Clear
 +
cboBoxName.ColumnCount = 2
 +
cboBoxName.ListWidth = "13 cm"
 +
cboBoxName.ColumnWidths = "3 cm; 10 cm"
 +
cboBoxName.ColumnHeads = True
 +
 +
cboBoxName.Clear
 +
cboBoxName.AddItem "P001"
 +
cboBoxName.List(0, 1) = "Product Name"
  
 
 
 
 

Revision as of 16:58, 16 January 2008

A ComboBox control combines the features of a TextBox control and a ListBox control.

About the ComboBox

Users can enter information in the text box portion or select an item from the list box portion of the control.

Use a combo box when you need a user to either select a list of suggested alternatives or to type his own , and use a list box if the user is required to select from a fixed number of items.

There is only one single type of a list box, but there are three types of combo boxes which can be selected with the style property value of 0(Drop Down Combo Box), 1(Simple Combo Box), and 2(Drop-Down List Box).

To add or delete items in a ComboBox control, use the AddItem or RemoveItem method. Set the List, ListCount, and ListIndex properties to enable a user to access items in the ComboBox. Alternatively, you can add items to the list by using the List property at design time.

A Scroll event will occur in a ComboBox control only when the contents of the dropdown portion of the ComboBox are scrolled, not each time the contents of the ComboBox change. For example, if the dropdown portion of a ComboBox contains five items and the top item is highlighted, a Scroll event will not occur until you press the down arrow six times (or the PGDN key once). After that, a Scroll event occurs for each press of the down arrow key. However, if you then press the up arrow key, a Scroll event will not occur until you press the up arrow key six times (or the PGUP key once). After that, each up arrow key press will result in a Scroll event.

Properties

Items are added or removed to combo and list boxes during both runtime and design time. If you want to add list items at design time, select the list property.

AddItem

List1.additem "Hello World" 'Add items
List1.additem "This is 2nd Item"
List1.additem "First item",0 'squeeze into 1st

RemoveItem

list1.removeitem 3 'Remove the fourth item

Clear

ist1.clear 'Clear the list box

ListCount

The number of items in a list is given by the listcount property.

ListIndex

The currently selected item's index can be returned with the listindex property. A listindex property of -1 indicates that no item has been selected

 

Multi-Columns Combo Box

The Visual BASIC 6.0 ComboBox does support multiple columns with no additional references necessary.

cboEData(4).AddItem rs1!PLValue
cboEData(4).List(0, 1) = rs1!PLID
cboBoxName.Clear
cboBoxName.ColumnCount = 2
cboBoxName.ListWidth = "13 cm"
cboBoxName.ColumnWidths = "3 cm; 10 cm"
cboBoxName.ColumnHeads = True

cboBoxName.Clear
cboBoxName.AddItem "P001"
cboBoxName.List(0, 1) = "Product Name"