Difference between revisions of "Documentation/DevGuide/Basic/List Box"
(Initial author Sun Microsystems, Inc.) |
(Correction : use "ListBox1" instead of "list box1", use oListBox instead of olist box. Added : getSelectedItemPos) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
|NextPage=Documentation/DevGuide/Basic/Combo Box | |NextPage=Documentation/DevGuide/Basic/Combo Box | ||
}} | }} | ||
− | {{DISPLAYTITLE:List Box}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Basic/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:List Box}} | ||
The list box control <idl>com.sun.star.awt.UnoControlListBox</idl> displays a list of items that the user can select one or more of. If the number of items exceeds what can be displayed in the list box, scroll bars automatically appear on the control. If the <code>Dropdown</code> property is set to <code>True</code>, the list of items is displayed in a drop-down box. In this case, the maximum number of line counts in the drop-down box are specified with the <code>LineCount</code> property. The actual list of items is controlled by the <code>StringItemList</code> property. All selected items are controlled by the <code>SelectedItems</code> property. If the <code>MultiSelection</code> property is set to <code>True</code>, more than one entry can be selected. | The list box control <idl>com.sun.star.awt.UnoControlListBox</idl> displays a list of items that the user can select one or more of. If the number of items exceeds what can be displayed in the list box, scroll bars automatically appear on the control. If the <code>Dropdown</code> property is set to <code>True</code>, the list of items is displayed in a drop-down box. In this case, the maximum number of line counts in the drop-down box are specified with the <code>LineCount</code> property. The actual list of items is controlled by the <code>StringItemList</code> property. All selected items are controlled by the <code>SelectedItems</code> property. If the <code>MultiSelection</code> property is set to <code>True</code>, more than one entry can be selected. | ||
It may be easier to use the <idl>com.sun.star.awt.XListBox</idl> interface when working with list boxes, because an item can be added to a list at a specific position with the <code>addItem</code> method. For example, an item is added at the end of the list by: | It may be easier to use the <idl>com.sun.star.awt.XListBox</idl> interface when working with list boxes, because an item can be added to a list at a specific position with the <code>addItem</code> method. For example, an item is added at the end of the list by: | ||
− | + | <source lang="oobas"> | |
− | Dim nCount As Integer | + | Dim nCount As Integer, oListBox As Object |
− | + | oListBox = oDialog.getControl("ListBox1") | |
− | nCount = | + | nCount = oListBox.getItemCount() |
− | + | oListBox.addItem( "New Item", nCount ) | |
− | + | </source> | |
Multiple items are added with the help of the <code>addItems</code> method. The <code>removeItems</code> method is used to remove items from a list. For example, the first entry in a list is removed by: | Multiple items are added with the help of the <code>addItems</code> method. The <code>removeItems</code> method is used to remove items from a list. For example, the first entry in a list is removed by: | ||
− | + | <source lang="oobas"> | |
Dim nPos As Integer, nCount As Integer | Dim nPos As Integer, nCount As Integer | ||
nPos = 0 | nPos = 0 | ||
nCount = 1 | nCount = 1 | ||
− | + | oListBox.removeItems( nPos, nCount ) | |
− | + | </source> | |
A list box item can be preselected with the <code>selectItemPos</code>, <code>selectItemsPos</code> and <code>selectItem</code> methods. For example, the first entry in a list box can be selected by: | A list box item can be preselected with the <code>selectItemPos</code>, <code>selectItemsPos</code> and <code>selectItem</code> methods. For example, the first entry in a list box can be selected by: | ||
− | + | <source lang="oobas"> | |
− | + | oListBox.selectItemPos( 0, True ) | |
− | + | </source> | |
The currently selected item is obtained with the <code>getSelectedItem</code> method: | The currently selected item is obtained with the <code>getSelectedItem</code> method: | ||
− | + | <source lang="oobas"> | |
Dim sSelectedItem As String | Dim sSelectedItem As String | ||
− | sSelectedItem = | + | sSelectedItem = oListBox.getSelectedItem() |
+ | </source> | ||
+ | The position of the currently selected item is obtained with the <code>getSelectedItemPos</code> method: | ||
+ | <source lang="oobas"> | ||
+ | Dim selectPos As Integer | ||
+ | selectPos = oListBox.getSelectedItemPos() | ||
+ | </source> | ||
+ | {{PDL1}} | ||
− | + | [[Category:Documentation/Developer's Guide/Basic and Dialogs]] | |
− | [[Category: Basic and Dialogs]] | + |
Revision as of 09:38, 3 December 2010
The list box control com.sun.star.awt.UnoControlListBox displays a list of items that the user can select one or more of. If the number of items exceeds what can be displayed in the list box, scroll bars automatically appear on the control. If the Dropdown
property is set to True
, the list of items is displayed in a drop-down box. In this case, the maximum number of line counts in the drop-down box are specified with the LineCount
property. The actual list of items is controlled by the StringItemList
property. All selected items are controlled by the SelectedItems
property. If the MultiSelection
property is set to True
, more than one entry can be selected.
It may be easier to use the com.sun.star.awt.XListBox interface when working with list boxes, because an item can be added to a list at a specific position with the addItem
method. For example, an item is added at the end of the list by:
Dim nCount As Integer, oListBox As Object oListBox = oDialog.getControl("ListBox1") nCount = oListBox.getItemCount() oListBox.addItem( "New Item", nCount )
Multiple items are added with the help of the addItems
method. The removeItems
method is used to remove items from a list. For example, the first entry in a list is removed by:
Dim nPos As Integer, nCount As Integer nPos = 0 nCount = 1 oListBox.removeItems( nPos, nCount )
A list box item can be preselected with the selectItemPos
, selectItemsPos
and selectItem
methods. For example, the first entry in a list box can be selected by:
oListBox.selectItemPos( 0, True )
The currently selected item is obtained with the getSelectedItem
method:
Dim sSelectedItem As String sSelectedItem = oListBox.getSelectedItem()
The position of the currently selected item is obtained with the getSelectedItemPos
method:
Dim selectPos As Integer selectPos = oListBox.getSelectedItemPos()
Content on this page is licensed under the Public Documentation License (PDL). |