[Solved] Select an item of listbox

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
klausk
Posts: 19
Joined: Thu May 28, 2009 9:07 pm

[Solved] Select an item of listbox

Post by klausk »

I would like that from a listbox the second value of the list is preset when starting the dialog. Is there a method to achieve this?

Code: Select all

Sub cbxVerzNameFuellen
Dim strEintraege(2)
Dim myItem as Object
strEintraege(0)="Inhaltsverzeichnis"
strEintraege(1)="Sheetverzeichnis"
strEintraege(2)="Honorarverzeichnis"
oDlg.getControl("cbxVerzName").additems(strEintraege(),1)
oDlg.getControl("cbxVerzName").getItem(1)'selcet the second item of the list

end sub
Last edited by MrProgrammer on Sun Apr 16, 2023 7:21 pm, edited 2 times in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OOo 3.1.X on Ubuntu 8.x + opensuse 11.1
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: how to select an item of listbox

Post by RoryOF »

In OpenOffice you will find a set of macros to manipulate listboxes
Access these by /Tools /Macros /Organize Macros /OpenOffice Basic : OpenOffice Macros : Tools: Listbox

Study these and you should get all the information you require.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: how to select an item of listbox

Post by JeJe »

You could add the items to the listbox in the IDE and also select the second item in the listbox properties.

If that's not possible see here:

https://www.openoffice.org/api/docs/com ... stBox.html

If you don't have MRI you should get that - and easily answer your own question with it.

viewtopic.php?t=49294
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to select an item of listbox

Post by JeJe »

Or a search for threads already answered...

viewtopic.php?t=7248

Edit: I'm sure there'll be other threads if that one's no good...

Edit2: And there's Pitonyak's free books... I presume it will be in there...

https://www.pitonyak.org/oo.php
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
klausk
Posts: 19
Joined: Thu May 28, 2009 9:07 pm

Re: How to select an item of listbox

Post by klausk »

Xray tolds me that there are now no select methods
OOo 3.1.X on Ubuntu 8.x + opensuse 11.1
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to select an item of listbox

Post by JeJe »

They all work for me.

selectItemPos selects/deselects the item at the specified position.
selectItemsPos selects/deselects multiple items at the specified positions.
selectItem

https://www.openoffice.org/api/docs/com ... stBox.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
klausk
Posts: 19
Joined: Thu May 28, 2009 9:07 pm

Re: How to select an item of listbox

Post by klausk »

I try this without of success

Code: Select all

Sub cbxVerzNameFuellen
Dim strEintraege(2)
Dim strVer as String
Dim Eintraege 'as String
Dim oListBoxQuelle as Object
strEintraege(0)="Inhaltsverzeichnis"
strEintraege(1)="Sheetverzeichnis"
strEintraege(2)="Honorarverzeichnis"
oListBoxQuelle=oDlg.getControl("cbxVerzName")
oListBoxQuelle.additems(strEintraege(),1)
xray oListBoxQuelle
Eintraege = oDlg.getControl("cbxVerzName").getItems'ItemCount
msgbox Eintraege
	for i=0 to Ubound(Eintraege)
		strVer=Eintraege(i)'jeweiligen Namen auslesen
		oListBoxQuelle.addItem(strVer,i)'füllen
	next
	oListBoxQuelle.selectItemPos(0,true)
end sub
OOo 3.1.X on Ubuntu 8.x + opensuse 11.1
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to select an item of listbox

Post by JeJe »

See the Main sub in this document.
listboxselteat.odt
(11.24 KiB) Downloaded 76 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
klausk
Posts: 19
Joined: Thu May 28, 2009 9:07 pm

Re: [Solved]How to select an item of listbox

Post by klausk »

thx so much for your superior service. have written macros years ago and am now no longer in practice
OOo 3.1.X on Ubuntu 8.x + opensuse 11.1
Post Reply