0

I am having a problem with OpenOffice.org ListBox Form control. I have built a small form (not dialog) that contains a textbox and ListBox and 2 buttons.

Sub AddToList_ButtonClicked()

Dim oThisDoc As Object
Dim oForms as Object
Dim oForm as Object 

oThisDoc = thisComponent.getDrawPage()
oForms = oThisDoc.getForms()
oForm = oForms.getByName("SimpleForm")

Dim oTextBox As Object
Dim oListBox As Object

oListBox = oForm.getByName("simpleListBox")
oTextBox = oForm.getByName("simpleTextBox").Text
oListBox.stringitemlist() = Array("One", "Two", "Three") '<--- Only possible way to add items to the ListBox Form Control :(

End Sub

Sub RemoveFromList_ButtonClicked()

Dim oThisDoc As Object
Dim oForms as Object
Dim oForm as Object 

oThisDoc = thisComponent.getDrawPage()
oForms = oThisDoc.getForms()
oForm = oForms.getByName("SimpleForm")

Dim oListBox As Object

oListBox = oForm.getByName("simpleListBox")

oListBox.stringitemlist()  '<--- contains array of items
oListBox.SelectedItems '<--- contains items selected for removal

End Sub

I would totally appreciate any solution for this problem!.

zapper
  • 181
  • 3
  • 15
  • It looks like a Word file is your form - is that correct? Is there any Base file connected to it? As you have found, the listbox array content is clunky; it's actually easier to work with if the form is connected to a Base file and the listbox content is determined by an SQL string. If there is a Base connection, it would probably be better to have your list of items in a Base table, mark them up as indicated by the form user's input, then `oListBox.refresh` to get it to show the updated list. If you want this in Word only - it seems your code works, what exactly is the question? – Lyrl Nov 12 '15 at 14:51

1 Answers1

0

Is this what you are looking for?

' Add items.
oListBox.StringItemList() = Array("One", "Two", "Three")
oListBox.insertItemText(oListBox.ItemCount, "Four")  ' This works even if oListBox starts out empty.
oListBox.insertItemText(oListBox.ItemCount, "Five")

' Remove the last item in the list.
oListBox.removeItem(oListBox.ItemCount - 1)

XrayTool shows that oListBox implements XItemList.

The form I used to test this code was in Writer, without any connection to Base.

Jim K
  • 12,824
  • 2
  • 22
  • 51