How to Programmatically add or remove items in ListBox FORM control

大城市里の小女人 提交于 2019-12-12 04:16:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!