[Solved] List Box - Select Items

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ktr73
Posts: 3
Joined: Thu Jun 26, 2008 8:06 pm

[Solved] List Box - Select Items

Post by ktr73 »

Hi All -

Totally new to OOo, so please forgive me if this is pretty easy (I come from a VBA background) ... I have a form set up in Base where whenever someone changes a particular combo box (cbx_account), it automatically updates a separate list box with new entries (lbx_lines). The problem is, I want all the items in the new list box selected by default but only one item is usually selected. Furthermore, this wouldn't be such a big problem except whenever I manually select all the items and then go to click on the "submit" button (a button I created as part of the form), it deselects the last item I had just selected and so it looks like (to the macro executed when the submit button is clicked) I didn't select all of them when I did!

If I could figure out a way to just automatically select all the items in the list box by default (i.e., via basic code) that would hopefully solve my problem. -Most- of the time (eg, maybe 95%) the user will want every item selected anyway, so doing this would also alleviate some work on their end as well.

Any ideas are greatly appreciated! Thanks,

Kevin
Last edited by ktr73 on Thu Jun 26, 2008 9:33 pm, edited 1 time in total.
OOo 2.4.X on Ubuntu 8.x + Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: List Box - Select Items

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
ktr73
Posts: 3
Joined: Thu Jun 26, 2008 8:06 pm

Re: List Box - Select Items

Post by ktr73 »

Hey -

That didn't seem to work (my list box provided an interface for OListBoxModel as opposed to XListBox, which is where the link pointed to). But it lead me to: http://www.oooforum.org/forum/viewtopic.phtml?t=67724, which in turn gave me the idea for the following code:

Code: Select all

Dim selections(Ubound(lbx_lines.StringItemList)) As Integer
For i = 0 To Ubound(lbx_lines.StringItemList)
	selections(i) = i
Next i
lbx_lines.SelectedItems = selections
And that seems to work! All the items are selected by default when running this code. Thanks for your help!

Kevin
OOo 2.4.X on Ubuntu 8.x + Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] List Box - Select Items

Post by Villeroy »

The model reflects the same properties you can set in the dialog designer. The running dialog has "living" controls.
The model: http://api.openoffice.org/docs/common/r ... Model.html

The living thing derived from a model: http://api.openoffice.org/docs/common/r ... stBox.html

Code: Select all

Sub run_Dialog1
oLib = DialogLibraries.Standard
Dlg = CreateUnoDialog(oLib.getByName("Dialog1"))
Dlg.setVisible(True)
REM now we have a visible window with controls
oCtrl = Dlg.getControl("ListBox")
oCtrl.selectItemPos(0)
Dlg.execute
End Sub
OK, this is not a perfect example. I would set the model's default selection before loading. But this makes more sense:

Code: Select all

sub someEvent(oEv)
caller = oEv.Source 'some other control
dlg = caller.getContext()
list = dlg.getControl("ListBox3")
list.selectItemPos(0)
end Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
ktr73
Posts: 3
Joined: Thu Jun 26, 2008 8:06 pm

Re: [Solved] List Box - Select Items

Post by ktr73 »

I think I get it. Thanks!
OOo 2.4.X on Ubuntu 8.x + Windows XP
Post Reply