Hi
LibreOffice’s database is relational. With such databases, multi-valued fields are indeed managed by related tables. This is why listboxes only allow multi-select if the control is not bound to a database field.
With listbox not bound to a database field, a macro can collect selected items, and assign them to a field.
In the following MultiSelect.odb the macro is associated to the click of the button.
Here is the code:
Sub MultiSelect(oEvt)
const sep = "|"
dim oForm as object, oListCtrl as object, oCtrl as object
Dim i as integer
oForm = oEvt.source.model.parent
oListCtrl = oForm.getByName("ListBox1")
oCtrl = oForm.getByName("Fruit")
with oListCtrl
select case ubound(.SelectedValues())
case -1
msgbox "no selection", 64, "Multiselect"
case 0
oCtrl.text = .SelectedValues(0)
oCtrl.commit
case > 0
oCtrl.text = ""
for i = 0 to ubound(.SelectedValues()) - 1
oCtrl.text = oCtrl.text & .SelectedValues(i) & sep
next i
oCtrl.text = oCtrl.text & .SelectedValues(i)
oCtrl.commit
case else
msgbox "This should not occur...", 64, "Multiselect"
end select
end with
end sub
As you can see, the separator |
is given at the beginning of the macro. You can replace by what you want…
Finally, as the listbox is not associated with a field, it is not cleared on record changing. The following macro allows for example to reset the list. It is associated with the form event “After changing”.
sub ChangeRecord(oEvt)
dim oForm as object, oListCtrl as object
oForm = oEvt.source
oListCtrl = oForm.getByName("ListBox1")
oListCtrl.SelectedValues() = array()
end sub
If this answers the question, thank you to click on the to mark it ANSWERED.
Regards