【问题标题】:How to Programmatically add or remove items in ListBox FORM control如何以编程方式在 ListBox FORM 控件中添加或删除项目
【发布时间】:2015-11-12 08:31:58
【问题描述】:

我在使用 OpenOffice.org 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 :(

结束子

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

结束子

我非常感谢任何解决这个问题的方法!

【问题讨论】:

  • 您的表单看起来像是 Word 文件 - 对吗?是否有任何基本文件连接到它?如您所见,列表框数组内容很笨重;如果表单连接到基本文件并且列表框内容由 SQL 字符串确定,则实际上更容易使用。如果有 Base 连接,最好将您的项目列表放在 Base 表中,按照表单用户输入的指示标记它们,然后 oListBox.refresh 让它显示更新的列表。如果您只希望在 Word 中使用它 - 您的代码似乎可以正常工作,问题到底是什么?

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


【解决方案1】:

这是你要找的吗?

' 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 没有任何连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-01
    • 2011-07-19
    • 1970-01-01
    • 2017-04-07
    • 2018-09-24
    • 2010-10-10
    • 2014-08-25
    • 1970-01-01
    相关资源
    最近更新 更多