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
Addendum to changing defaults in Listboxes
Addendum to changing defaults in Listboxes
- Attachments
-
- DefaultToListBox.odb
- (13.53 KiB) Downloaded 131 times
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
-
- Volunteer
- Posts: 1548
- Joined: Wed Jun 24, 2015 12:56 am
- Location: Colorado, USA
Re: Addendum to changing defaults in Listboxes
Yes, spaces, spelling and even capitalization are important when addressing the API.I am also wondering if the space in the property name could be another problem.
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
oControl.DefaultSelection = oControl.Boundfield.Value
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
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
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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Re: Addendum to changing defaults in Listboxes
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
cheers
Gerhard
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend