Hallo Oliver,
Das Makro läuft zwar, aber ich glaube anders als gewollt. Die Items werden zwar richtig rausgegeben aber in der Box nicht angezeigt. Nur das ausgewählte Element. Doch das ist nicht wo wichtig.

Aber ich hatte von einer Listbox in einem Dialog gesprochen. DA funktionierte das ganze nicht.

Horst


Am 15.02.2016 um 19:40 schrieb Oliver Brinzing:
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


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

Antwort per Email an