Addendum to changing defaults in Listboxes

Creating and using forms

Addendum to changing defaults in Listboxes

Postby gkick » Fri Oct 04, 2019 8:26 am

Hello,

How to change a property of a listbox control
Am evaluating a number of options to establish changing defaults for fields. The options so far looked at were setting the table fields default via sql which is no good if a form uses a listbox, an alternative would be cloning fields or records and yet another option was to sort of synchronise 2 listboxes using a filter table, but why use 2 if it possibly can be done with just one listbox.
I thought since there is a default selection property associated with listboxes it might be possible to change this property once the selection changes by attaching a short sub to the change event in order for the last selected value to stick until changed again. Not up to speed yet with coding but experimenting with cut paste modify whatever code snippets I come across.
Here is my latest attempt throwing up an error and I am also wondering if the space in the property name could be another problem.
Any hints will be appreciated, db in the attachment
Thks
Attachments
DefaultToListBox.odb
(13.53 KiB) Downloaded 17 times
oops.JPG
Libre Office 6.2 on Windows 10 HSQL 2.5 backend
gkick
 
Posts: 174
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Addendum to changing defaults in Listboxes

Postby UnklDonald418 » Sat Oct 05, 2019 10:40 pm

I am also wondering if the space in the property name could be another problem.

Yes, spaces, spelling and even capitalization are important when addressing the API.

Since you are using an event associated with the listbox named "country", finding the control is quite simple.
Once you have the control it is also simple to obtain the Boundfield.Value.
If you use MRI to inspect DefaultSelection you will see that it is not just a simple value so an assignment like
Code: Select all   Expand viewCollapse view
oControl.DefaultSelection = oControl.Boundfield.Value

won't work, but it does appear to be a one element array.
I don't think this is your final answer but the following does appear to at least temporarily change the value in DefaultSelection.

Code: Select all   Expand viewCollapse view
Sub Testit (oEv as Object)
Dim BV(0) as Integer

'If Not Globalscope.BasicLibraries.isLibraryLoaded("MRILib") Then
'      Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
'End If
'oMRI = CreateUnoService( "mytools.Mri" )
REM  get the control from the event.
oControl= oEv.Source
'oMRI.inspect oControl
REM  store the value in an array
BV(0) = oControl.Boundfield.Value 
REM assign the array to DefaultSelection
oControl.DefaultSelection = BV   

End Sub


I included the MRI code but it is commented out. Remove the apostrophes from the MRI related lines to enable the MRI tool and you can inspect the oControl object each time.the macro executes.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.7 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1280
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Addendum to changing defaults in Listboxes

Postby gkick » Sun Oct 06, 2019 5:26 am

Thank you very much UnclDonald418. I need to study the MRI in more detail. At the moment the selected value is correct, however what I noticed when entering a default value manually within the control, base changes it to a string so 1 becomes "1" in the properties list. Anyway have some good pointers, very much appreciated !

cheers
Gerhard
Libre Office 6.2 on Windows 10 HSQL 2.5 backend
gkick
 
Posts: 174
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile


Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest