如何以编程方式添加或删除ListBox FORM控件中的项目 [英] How to Programmatically add or remove items in ListBox FORM control

查看:113
本文介绍了如何以编程方式添加或删除ListBox FORM控件中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用OpenOffice.org ListBox表单控件时遇到了问题. 我建立了一个小窗体(不是对话框),其中包含一个文本框和ListBox以及2个按钮.

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()

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()

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

结束子

对于此问题的任何解决方案,我将不胜感激!.

I would totally appreciate any solution for this problem!.

推荐答案

这是您要寻找的吗?

' 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实现了

XrayTool shows that oListBox implements XItemList.

我用来测试此代码的表单是在Writer中编写的,与Base没有任何联系.

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

这篇关于如何以编程方式添加或删除ListBox FORM控件中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆