OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

OOo basic beginner : how to set the value of a ListBox ?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
InfoSysArchi
General User
General User


Joined: 17 Oct 2007
Posts: 19

PostPosted: Thu Oct 18, 2007 10:45 am    Post subject: OOo basic beginner : how to set the value of a ListBox ? Reply with quote

Hi,

I'm just starting with OOo basic (OOo 2.3 on Windows XP).

Is there a way, from Basic, to define the value of a List Box on a Form ?
- either by index (eg. the 4th element of the list)
- or by value (eg. the item which value is myValue).

Note : the listbox is not bound to any database field.

One could think of writing in myListBoxControl.currentValue, but this property is read-only, not read-write, and can't be used in this purpose.

Second question : how to get all the possible properties and methods of the ListBox control, or others ?

Thanks and regards

Marc

---- Code sample to illustrate the question -----
' Assuming myForm contain myListBox

Sub setListValue
Dim oDoc As Object
Dim oDrawPage As Object
Dim oForm As Object
Dim oControl as Object

oDoc = thisComponent
oDrawPage = oDoc.DrawPage
oForm = oDrawPage.Forms.GetByname("myForm")
oControl = oForm.getbyname("myListBox")
msgbox oControl.currentValue 'this works, which shows the control is correctly returned
' But then, how can the value of the ListBox be selected ?
oValue.<WhichPropertyOrMethodToUse?>
End Sub


Last edited by InfoSysArchi on Mon Oct 22, 2007 8:00 am; edited 1 time in total
Back to top
View user's profile Send private message
uros
Super User
Super User


Joined: 22 May 2003
Posts: 601
Location: Slovenia

PostPosted: Thu Oct 18, 2007 9:14 pm    Post subject: Re: OOo basic beginner : how to set the value of a ListBox ? Reply with quote

InfoSysArchi wrote:
Second question : how to get all the possible properties and methods of the ListBox control, or others ?

Download X-Ray
Uros
Back to top
View user's profile Send private message
InfoSysArchi
General User
General User


Joined: 17 Oct 2007
Posts: 19

PostPosted: Mon Oct 22, 2007 8:02 am    Post subject: Reply with quote

Hi Uros

Thank you for the pointer to X-Ray, it is very useful.

But I still could not find how to change the value of a ListBox. Could anyone help ?

Please note, in order to make the question as understandable as possible, I rephrased slightly the original post

Thank you for your help

Best regards.

Marc
Back to top
View user's profile Send private message
JZA
OOo Advocate
OOo Advocate


Joined: 01 Feb 2003
Posts: 432
Location: Mexico

PostPosted: Mon Oct 22, 2007 12:24 pm    Post subject: Reply with quote

This won't answer your question but hopefully shed some light:
http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XListBox.html

This is the documentation for the ListBox widget and you have these following methods:
getSelectedItemPos
getSelectedItemsPos
addItem
addItems
removeItems
...

Code:
'Author: Marc Messeant
'email: marc.liste@free.fr
'To copy one AutoText From a group to an other one
'ListBox1 : The initial group
'ListBox2 : the Destination Group
'ListBox3 : The Element of the initial group to copy
'ListBox4 : The Element of the Destination group (for information only)

Dim ODialog as object
Dim oAutoText as object

' This subroutine opens the Dialog and initialize the lists of Group

Sub OuvrirAutoText
  Dim aTableau() as variant
  Dim i as integer
  Dim oListGroupDepart as object, oListGroupArrivee as object

  oDialog = LoadDialog("CG95","DialogAutoText")
  oListGroupDepart = oDialog.getControl("ListBox1")
  oListGroupArrivee = oDialog.getControl("ListBox2")
  oAutoText = createUnoService("com.sun.star.text.AutoTextContainer")
  aTableau = oAutoText.getElementNames()
  oListGroupDepart.removeItems(0,oListGroupDepart.getItemCount())
  oListGroupArrivee.removeItems(0,oListGroupArrivee.getItemCount())
  For i = LBound(aTableau()) To UBound(aTableau())
    oListGroupDepart.addItem(aTableau(i),i)
    oListGroupArrivee.addItem(aTableau(i),i)
  Next
  oDialog.Execute()
End Sub

'The 3 routines are called when the user selects one group to
'initialize the lists of AutoText elements for each group
Sub ChargerList1()
  ChargerListeGroupe("ListBox1","ListBox3")
End Sub
Sub ChargerList2()
  ChargerListeGroupe("ListBox2","ListBox4")
End Sub

Sub ChargerListeGroupe(ListGroupe as string,ListElement as string)
  Dim oGroupe as object
  Dim oListGroupe as object
  Dim oListElement as object
  Dim aTableau() as variant
  Dim i as integer

  oListGroupe = oDialog.getControl(ListGroupe)
  oListElement = oDialog.getControl(ListElement)
  oGroupe = oAutoText.getByIndex(oListGroupe.getSelectedItemPos())
  aTableau = oGroupe.getTitles()
  oListElement.removeItems(0,oListElement.getItemCount())
  For i = LBound(aTableau()) To UBound(aTableau())
    oListElement.addItem(aTableau(i),i)
  Next
End Sub

'This routine transfer one element of one group to an other one
Sub TransfererAutoText()
  Dim oGroupDepart as object,oGroupArrivee as object
  Dim oListGroupDepart as object, oListGroupArrivee as object
  Dim oListElement as object
  Dim oElement as object
  Dim aTableau() as string
  Dim i as integer

  oListGroupDepart = oDialog.getControl("ListBox1")
  oListGroupArrivee = oDialog.getControl("ListBox2")
  oListElement = oDialog.getControl("ListBox3")
  i =oListGroupArrivee.getSelectedItemPos()
  If oListGroupDepart.getSelectedItemPos() = -1 Then
    MsgBox ("Vous devez sélectionner un groupe de départ")
    Exit Sub
  End If
  If oListGroupArrivee.getSelectedItemPos() = -1 Then
    MsgBox ("Vous devez sélectionner un groupe d'arrivée")
    Exit Sub
  End If
  If oListElement.getSelectedItemPos() = -1 Then
    MsgBox ("Vous devez sélectionner un élément à copier")
    Exit Sub
  End If
  oGroupDepart = oAutoText.getByIndex(oListGroupDepart.getSelectedItemPos())
  oGroupArrivee = oAutoText.getByIndex(oListGroupArrivee.getSelectedItemPos())
  aTableau = oGroupDepart.getElementNames()
  oElement = oGroupDepart.getByIndex(oListElement.getSelectedItemPos())
  If oGroupArrivee.HasByName(aTableau(oListElement.getSelectedItemPos())) Then
    MsgBox ("Cet élément existe déja")
    Exit Sub
  End If
  oGroupArrivee.insertNewByName(aTableau(oListElement.getSelectedItemPos()),_
    oListElement.getSelectedItem(),oElement.Text)
  ChargerListeGroupe("ListBox2","ListBox4")
End Sub

_________________
Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group