如何以编程方式添加或删除ListBox FORM控件中的项目

时间:2015-11-12 08:31:58

标签: openoffice.org openoffice-writer listbox-control openoffice-base

我遇到OpenOffice.org ListBox Form控件的问题。 我已经构建了一个包含文本框和ListBox以及2个按钮的小表单(不是对话框)。

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

我完全赞赏这个问题的任何解决方案!。

1 个答案:

答案 0 :(得分:0)

这是你在找什么?

' 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表明oListBox实现了XItemList

我用来测试此代码的表单是在Writer中,没有任何与Base的连接。