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

Reading & refreshing ListBox

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


Joined: 23 Jan 2004
Posts: 10

PostPosted: Fri Feb 13, 2004 2:43 am    Post subject: Reading & refreshing ListBox Reply with quote

In Write I created a dialog wit a listbox ('profiles')
On the dialog there is a [delete] button to delete an item.
The 'click on [delete]' is processed by routine DeleteProfile (while the dialog is not closed)

DeleteProfile :

Code:

Sub DeleteProfile
  ...
  id = 0
  oProfileList = oProjectDialog.getControl("profiles")
  ...
  sSQL = "SELECT * FROM personen WHERE profile = '" + oProfileList.GetSelectedItem + "'"
  MsgBox(sSQL)
  ResultSet = Statement.executeQuery(sSQL)
  If Not IsNull(ResultSet) Then
    ' ******** Does record exist?
    While ResultSet.next
      id = ResultSet.getString(1)
    Wend
  Endif
  ...
  ' --> here I delete the record if id > 0
  ' --> here I have to delete the item in the list & refresh the list
  ...
End Sub


oProfileList.GetSelectedItem is returning a empty string. If I call oProfileList.GetSelectedItem after clicking on OK, the result is a valid listbox entry.

So:

1 - how to get the selected item during dialog activation?
2 - and how can I delete an item in DeleteProfile and refresh the list?

Regards,
Martijn
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Sat Feb 14, 2004 9:55 am    Post subject: Reply with quote

Quote:
1 - how to get the selected item during dialog activation?
I can't replicate your problem. My actions were
1. create a dialog (Dialog1) with a listbox (ListBox1) and button (CommandButton1)
2. create macro code
Code:
global oDialog1 as object
Sub Dialog1Show
DialogLibraries.LoadLibrary( "Standard" )
oDialog1 = CreateUnoDialog( DialogLibraries.Standard.Dialog1 )
oDialog1.Execute()
End Sub
Sub DeleteProfile
   oProfileList = oDialog1.getControl("ListBox1") 'dialog control
  sSQL = "SELECT * FROM personen WHERE profile = '" + oProfileList.GetSelectedItem + "'"
  MsgBox(sSQL)
End Sub
3. Assign DeleteProfile sub to buttonpressed event of commandbutton1
4. Show the dialog by executing the macro Dialog1Show from the document
5. Select an entry from the displayed list
6. Press the command button and SSql is displayed as expected...

Quote:
2 - and how can I delete an item in DeleteProfile and refresh the list?


Have a look at the example of Dialog in the StarOffice Programmer's Tutorial (5.6 Forms and Controls) this shows the use of listeners and callbacks.
Back to top
View user's profile Send private message
Martijn Wenke
General User
General User


Joined: 23 Jan 2004
Posts: 10

PostPosted: Mon Feb 16, 2004 6:30 am    Post subject: Listbox problem fixed Reply with quote

The Listbox problem is fixed.

I use the same construction as in your sample: a global dialog object.
I made the mistake to create the Dialog again in the click routine (so I was working with a copy).
Next problem to solve is the ListBox refreshing.

Regards,
Martijn
Back to top
View user's profile Send private message
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