Here is a simple macro that populates the ListBox1 in the Dialog1 dialog window with words from the "Word" column in the "wordlist" table in the BaseDB database.
Code: Select all
Sub PopulateListBox()
DBContext=createUnoService("com.sun.star.sdb.DatabaseContext")
If not DBContext.hasByName("WriterDB") then
MsgBox (ConnectionFailedMessage, , "Connection failed!") : End
End If
DataSource=DBContext.getByName("BaseDB")
ConnectToDB=DataSource.GetConnection ("","")
SQLResult=createUnoService("com.sun.star.sdb.RowSet")
SQLQuery="SELECT ""ID"", ""Word"" FROM ""wordlist"""
SQLResult.activeConnection = ConnectToDB
SQLResult.Command = SQLQuery
SQLResult.execute
exitOK=com.sun.star.ui.dialogs.ExecutableDialogResults.OK
DialogLibraries.LoadLibrary("Standard")
Library=DialogLibraries.GetByName("Standard")
TheDialog=Library.GetByName("Dialog1")
Dialog=CreateUnoDialog(TheDialog)
DialogField=Dialog.GetControl("ListBox1")
While SQLResult.next
ListBoxItem = SQLResult.getString(2)
DialogField.additem(ListBoxItem, DialogField.ItemCount)
Wend
If Dialog.Execute=exitOK Then
CurrentItemName=DialogField.SelectedItem
End If
End Sub
Kind regards,
Dmitri