Difference between revisions of "Documentation/DevGuide/Basic/Combo Box"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
m
 
Line 11: Line 11:
  
 
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 <code>Dropdown</code> property to <code>True</code>. The actual list of items is accessible through the <code>StringItemList</code> property. The text displayed in the text field of the combo box is controlled by the <code>Text</code> 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 <code>Text</code> property:
 
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 <code>Dropdown</code> property to <code>True</code>. The actual list of items is accessible through the <code>StringItemList</code> property. The text displayed in the text field of the combo box is controlled by the <code>Text</code> 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 <code>Text</code> property:
 
+
<source lang="oobas">
 
   Function GetSelectedItem( oComboBoxModel As Object ) As String
 
   Function GetSelectedItem( oComboBoxModel As Object ) As String
 
       GetSelectedItem = oComboBoxModel.Text
 
       GetSelectedItem = oComboBoxModel.Text
 
   End Function
 
   End Function
 
+
</source>
 
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 <code>Autocomplete</code> property to <code>True</code>. It is recommended to use the <idl>com.sun.star.awt.XComboBox</idl> interface when accessing the items of a combo box:
 
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 <code>Autocomplete</code> property to <code>True</code>. It is recommended to use the <idl>com.sun.star.awt.XComboBox</idl> interface when accessing the items of a combo box:
 
+
<source lang="oobas">
 
   Dim nCount As Integer
 
   Dim nCount As Integer
 
   Dim sItems As Variant
 
   Dim sItems As Variant
Line 31: Line 31:
 
   sItems = Array( "Item1", "Item2", "Item3", "Item4", "Item5" )
 
   sItems = Array( "Item1", "Item2", "Item3", "Item4", "Item5" )
 
   oComboBox.addItems( sItems, 0 )
 
   oComboBox.addItems( sItems, 0 )
 
+
</source>
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Basic and Dialogs]]
 
[[Category:Documentation/Developer's Guide/Basic and Dialogs]]

Latest revision as of 10:04, 22 October 2009



The combo box control com.sun.star.awt.UnoControlComboBox 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 com.sun.star.awt.XComboBox 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