Hallo Horst,

Szenario: In der ersten Tabelle eines Tabellendokuments ist ein Listenfeld mit dem Namen "Listenfeld 1" vorhanden.
Dann sollte das Beispiel funktionieren:

REM  *****  BASIC  *****
Sub ListBoxExample()
        Dim oDoc as Object
        Dim oView as Object
        Dim oDrawPage as Object
        Dim oForms as Object
        Dim oListBoxModel as Object
        Dim oListBoxControl as Object
        Dim mItems()
        
        mItems() = Array("1","2","3")
        
        oDoc = ThisComponent
        oView = oDoc.getCurrentController()
        
        ' jede Tabelle hat eine DrawPage        
        oDrawPage = oDoc.getDrawPages.getByIndex(0)

        If oDrawPage.hasElements() Then
                ' jede DrawPage kann mehrere Forms haben ...
                oForms = oDrawPage.getForms()
                If oForms.hasElements Then
                        ' i.d.R. "Formular"
                        oForm = oForms.getByIndex(0)
                        If oForm.hasByName("Listenfeld 1") Then
                                ' UnoControlListBoxModel - 
com.sun.star.awt.XItemList
                                oListBoxModel = oForm.getByName("Listenfeld 1")
                                oListBoxModel.Enabled = True
                                oListBoxModel.DropDown = True
                                
                                oListBoxModel.StringItemList() = mItems()
                                oListBoxModel.insertItemText(0, "Hello")
                                oListBoxModel.insertItemText(4, "World")
                                oListBoxModel.selectedItems() = Array(4)

                                ' UnoControlListBox - com.sun.star.awt.XListBox
                                oListBoxControl = 
oView.getControl(oListBoxModel)
MsgBox oListBoxControl.selectedItem & Chr(13) & oListBoxControl.selectedItemPos & Chr(13) & oListBoxControl.ItemCount

                                oListBoxControl.selectItemPos(2, True)
MsgBox oListBoxControl.selectedItem & Chr(13) & oListBoxControl.selectedItemPos & Chr(13) & oListBoxControl.ItemCount
        
                                oListBoxControl.addItem("XXX", 5)

                                oListBoxControl.selectItemPos(1, True)
MsgBox oListBoxControl.selectedItem & Chr(13) & oListBoxControl.selectedItemPos & Chr(13) & oListBoxControl.ItemCount
                        EndIf
                EndIf
        EndIf
End Sub

Gruß
Oliver


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Antwort per Email an