You could also try something like this:

Sub DoThing
    Dim Form As Object
    Dim ListBox As Object
    Dim Controller As Object
    Dim ListBoxControlModel As Object

    ' Get controller for the current document
    Controller = ThisComponent.getCurrentController()

    ' Assuming first or only form
    Form = ThisComponent.Drawpage.Forms.getByIndex(0)
    ListBox = Form.getByName("ListBoxName") 'I prefer getByName().
    ListBoxControlModel = Controller.getControl(ListBox)

    ListBoxControlModel.selectItem("ItemTextToSelect", True)
    ' If it is a database/data form, you will want to do the following.
    ' Otherwise, you might not need the next line.
End Sub

I don't know if the above is quicker or easier than what Ariel suggested, but its the way that I typically do it in database forms when i need to select a particular item in a list box, usually based on some other control value.

Also, in a database, all new records show the empty selection for the list box, because the data value in the control is not bound to anything, yet. Thus, you need the ListBox.commit() line above to tell the form to update the data for this field. If you don't do the commit(), this field will be null when you save the record.


To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to