Hi, I want to show in a treetable or combobox unique values from a MySQL table.
For example, if in column 1 of the table, I have 3 rows named “A”, and 3 rows named “B”, I would like to show only once “A” and “B”, instead of six different options (that is what I have so far)…
It’s almost impossible to know how to guide you, as I don’t know how you are populating the container behind the combo box - there are many ways to do this.
If you are retrieving just the names in a SQL statement, change the SQL from
ComboBox combo1 = new ComboBox("Please select a name");
combo1.setContainerDataSource(contenedor);
combo1.setItemCaptionPropertyId("firstName");
layout.addComponent(combo1);
where “contenedor” is a SQLContainer for a table like the on shown below. As you can see, the name "Juan appears twice and I would like to show it only once. Is it possible?
Well, the most important bit of code is the bit you haven’t shown us! How are you creating the container?
I’ve never used SQLContainer myself, so I don’t know exactly how it works. The contents of the container control what appears in the combo box, so you need to limit the contents of the container. A quick look at the source code for SQLContainer suggests that something like the following (untested, probably doesn’t even compile) would do.
Query query = new FreeformQuery("SELECT DISTINCT FIRSTNAME FROM PEOPLE",null, connectionPool);
SQLContainer c = new SQLContainer(query);
If you need to use the same container for two different tables/combo boxes, then this approach wouldn’t work.