Database Guide
In this example, you will learn how to display all the result rows as
strings in a list box.
When you have finished, you will have a window that looks like this:

- Begin by creating a new visual part with a list box in the window.
- Add a multi-row query to the free-form surface, and use the same SQL query
you used in the last example:
SELECT STAFF.NAME, STAFF.COMM, STAFF.DEPT, STAFF.ID,
STAFF.JOB, STAFF.SALARY, STAFF.YEARS
FROM STAFF
- Tear off the resultTable attribute from the multi-row
query.
- Connect the window's openedWidget event to the
query's executeQuery action and connect the
rowsAsStrings attribute of the result table to the items
attribute of the list box.
- When you test the visual part, it appears as follows:

Notice that all of the columns are concatenated, but separated by left and
right brackets. Since this probably isn't the appearance you want,
you can write a script that formats the results more neatly by concatenating
the name and job columns and displaying just those columns in the list.
To create this script and add it to your visual part, follow these
steps:
- Switch to the Script Editor and create the following script:
formatRows
| items address rows |
items := OrderedCollection new.
((self subpartNamed: 'resultTable of Multi-row Query1')
valueOfAttributeNamed: #rows selector: #'IS_rows')
do: [:each |
each isNil ifFalse: [
address := (each at: 'NAME') trimBlanks,
', ', (each at: 'JOB').
items add: address.]].
^items
For each row of the result table, this script concatenates the name and job
values, separated by a comma. As it iterates through the rows, each of
these strings is added to an ordered collection, which is returned at the end
of the script.
- To display this collection of strings in the list box, change your
connections as follows:
- Delete the connection between the items attribute of the list
box and the rowsAsStrings attribute of the result table.
- Add an attribute-to-script connection from the items attribute
of the list to the formatRows script.
- On the connection dialog, select the More dependencies push
button.
- Select the result table part and the self attribute, and select
Add row. This makes the script run whenever the result table
changes.
- Select the OK push button on the connection dialogs to return
to the Composition Editor.
Your connections should look like the following:

- Test your work, and you should see the name and job strings displayed
neatly in the list.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]