Combo Box

From Apache OpenOffice Wiki
Jump to: navigation, search

The combo box control presents a list of choices to the user. Additionally, it contains a text field allowing the user to input a selection that is not on the list. A combo box is used when there is only a list of suggested choices, whereas a list box is used when the user input is limited only to the list.

The features and properties of a combo box and a list box are similar. Also in a combo box the list of items can be displayed in a drop-down box by setting the Dropdown property to True. The actual list of items is accessible through the StringItemList property. The text displayed in the text field of the combo box is controlled by the Text property. For example, if a user selects an item from the list, the selected item is displayed in the text field and is obtained from the Text property:

  Function GetSelectedItem( oComboBoxModel As Object ) As String
      GetSelectedItem = oComboBoxModel.Text
  End Function

When a user types text into the text field of the combo box, the automatic word completion is a useful feature and is enabled by setting the Autocomplete property to True. It is recommended to use the interface when accessing the items of a combo box:

  Dim nCount As Integer
  Dim sItems As Variant
  REM get control
  oComboBox = oDialog.getControl("ComboBox1")
  REM first remove all old items from the list
  nCount = oComboBox.getItemCount()
  oComboBox.removeItems( 0, nCount )
  REM add new items to the list
  sItems = Array( "Item1", "Item2", "Item3", "Item4", "Item5" )
  oComboBox.addItems( sItems, 0 )
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages