Hi all, I'm trying from a lot of days to create a multiselect listbox; data come from a sql query, like this:
select "column1","ID" from "table" where "otherfield"="something";
The listbox seems to work, data appears (data from column1) and I can do a multiselect. But, for having the
multiselect behaviour, I had to blank the field about the "bound" column (if there are other better ways to do that,
please let me know ...). The problem is that I can easily get the selected items (the data from column1) but NOT
the data from ID ... and data from column1 is not unique. So I can't get the IDs of the selected items.
Ok, maybe I can recover the ID with a query on database, applying the same where condition; but I really hope there's
a better way to do that (without building and populating the listbox directly from basic)
My english is poor, like my programming experience, so I hope that my explaination is "clear". If not, please let me know
and I'll try to explain better
Thank you
Marco
[Solved] Read second field on multi select listbox
[Solved] Read second field on multi select listbox
Last edited by nmarco on Thu Nov 05, 2009 6:01 pm, edited 1 time in total.
OpenOffice 3.1 on Windows XP and Linux
Re: Read second field on multi select listbox
Please go through this thread Read the second column in a listbox. Note that you need to bound your list box to a table field to be able to see the selected "ID"s. I tried the same thing a week ago and I changed the following two properties of the list box: 'Dropdown: No' and 'Multiselection: Yes'. I made the control of the ListBox on the form a few rows high so a scroll bar becomes visible. Note that only the ID of the first row selected will go into the bound field.
It's Microsoft marketing that tells you computers are qualified for non-technicians
W11 22H2 (build 22621), LO 7.4.2.3(x64)
W11 22H2 (build 22621), LO 7.4.2.3(x64)
Re: Read second field on multi select listbox
Thank you very much eremmel, but I've already read that post and tried what they say. But this technique is not good for my problem:
- you said that I get the ID of the first row selected only (and I need the IDs of every line selected)
- I'm unable to have a multiselection if I set a bound column, even if I set 'Dropdown: No' and 'Multiselection: Yes' (I tried several times). I don't know why,
maybe I'm doing something wrong, maybe it depends from the source table of the main form (or the relationships that table has with other tables of the
database)
Please tell me if I'm saying something wrong
The only solution I have, for now, is a "poor man solution": I'll set the width of the listbox, and I'll put as source data for it something like:
select "column1"||' '||"ID" from "table" where ....
So the ID won't appear to the final user, but I can get from all the lines selected.
Obviously I don't like this solution but for now it's the only "quick & dirty" one I have.
I think it's strange that I can look for every column of the source data of a form but not the columns of a listbox (it would be good if there was, for the listbox or other
controls something like oEvent.source.model.columns.getbyname("ID") returning an array); and I think it's strange that I can't do multiselection if bound column is set.
And openoffice documentation doesn't help at all for the problem "How to handle a multiselection listbox". Is there a place where I can tell suggestions to the openoffice team ?
Thank you
Marco
- you said that I get the ID of the first row selected only (and I need the IDs of every line selected)
- I'm unable to have a multiselection if I set a bound column, even if I set 'Dropdown: No' and 'Multiselection: Yes' (I tried several times). I don't know why,
maybe I'm doing something wrong, maybe it depends from the source table of the main form (or the relationships that table has with other tables of the
database)
Please tell me if I'm saying something wrong
The only solution I have, for now, is a "poor man solution": I'll set the width of the listbox, and I'll put as source data for it something like:
select "column1"||' '||"ID" from "table" where ....
So the ID won't appear to the final user, but I can get from all the lines selected.
Obviously I don't like this solution but for now it's the only "quick & dirty" one I have.
I think it's strange that I can look for every column of the source data of a form but not the columns of a listbox (it would be good if there was, for the listbox or other
controls something like oEvent.source.model.columns.getbyname("ID") returning an array); and I think it's strange that I can't do multiselection if bound column is set.
And openoffice documentation doesn't help at all for the problem "How to handle a multiselection listbox". Is there a place where I can tell suggestions to the openoffice team ?
Thank you
Marco
OpenOffice 3.1 on Windows XP and Linux
Re: Read second field on multi select listbox
Hello
I cannot complete follow you, but maybe the combo box is the best choice for you.
Multiselect does not work in a database when bound to a field; for a list or combo box.
Romke
I cannot complete follow you, but maybe the combo box is the best choice for you.
Multiselect does not work in a database when bound to a field; for a list or combo box.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Read second field on multi select listbox
I did not state that you get only the ID of the first row selected. But the concept of a list box is such that the ID of the selected row (the first row, with multiselect) is bound to the field of the table you specify. That does not mean that you can not get all the IDs corresponding to the rows selected when multiselect is enabled but you need some macro for this. When you start playing around with macro's you might use Xray (or MRILib) to analyze the object structure. The issue is that the property MultiSelection is reset to false. I used the following macro to fix that: Note: my listbox is called "ToBook" and this macro is bound to the ListBox's event "When Reveiving Focus".
I used a very simple macro to examine the result of a multi selection:
In xray window you can see what indexes are selected with the myListBox.SelectedItem (String[]) property:
The String[] myListBox.ValueItemList contains the "ID"s:
Code: Select all
Sub ToBook_WhenReceivingFocus(e as Object)
e.Source.Model.MultiSelection = true
End Sub
I used a very simple macro to examine the result of a multi selection:
Code: Select all
Sub ToBook_Changed(e as Object)
Dim myListBox as Object
myListBox = e.Source.Model
xray(myListBox)
End Sub
It's Microsoft marketing that tells you computers are qualified for non-technicians
W11 22H2 (build 22621), LO 7.4.2.3(x64)
W11 22H2 (build 22621), LO 7.4.2.3(x64)
Re: Read second field on multi select listbox
Thank you eremmel ! It works perfectly! I didn't think to "force" the MultiSelection value to "true" using a macro, and this solved
everything. It would be great if openoffice could handle the sql insert/delete of the selected values in the table, but I think
that it's not implemented (yet), but I think it's not difficult use a macro for that.
Thank you vary much, I spent nights on this problem And sorry for the misunderstanding
For RPG: thank you for the answer
Marco
everything. It would be great if openoffice could handle the sql insert/delete of the selected values in the table, but I think
that it's not implemented (yet), but I think it's not difficult use a macro for that.
Thank you vary much, I spent nights on this problem And sorry for the misunderstanding
For RPG: thank you for the answer
Marco
OpenOffice 3.1 on Windows XP and Linux