Как программно добавлять или удалять элементы в элементе управления ListBox FORM
У меня проблема с элементом управления формой OpenOffice.org ListBox. Я построил небольшую форму (не диалоговое окно), которая содержит текстовое поле и 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 ответ
Это то, что вы ищите?
' 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.