问题
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!.
回答1:
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.
来源:https://stackoverflow.com/questions/33667166/how-to-programmatically-add-or-remove-items-in-listbox-form-control