The Ol’ Hidden Items in the Dddw Problem Part II
We all eventually need to build a datawindow where the contents of a drop down list is dependent on the value of another column.
Filtering the available selections in the dddw for the current row is straight forward, just add the necessary filtering script in the RowFocusChanged and ItemChanged events. (See DDDW Contents Based on the Value of Another Column for more information regarding this. ) But if you have a tabular view, problems may soon become apparent with dependent columns in some rows displaying code values instead of descriptions.
In our example, we have an application keeping track of inventory at a Ford dealership. In the GUI, we are simply listing which cars and colors are currently in stock. Our data model has three tables: MODEL, COLOR, and MODEL_COLOR_XREF to determine which colors are available for the different car models. Details of the data model used for this example. The color column saves the COLOR_ID in the inventory table, but we want the COLOR_DESC to display in the GUI. Here is what we want the GUI to look like:
The first row contains a gray Ford Fusion. When the row changes to the second row, and a Ford Contour is selected, the color description (“Gray”) of the first car disappears and its COLOR_ID “5″ is displayed instead. This is because when the dddw for the color is filtered for the current car model, no “Gray” appears in MODEL_COLOR_XREF for the “Contour”. Since all rows share the same dddw, there is no longer a “Gray” row available for the Contour to display.
The third row contains a Model T. Because the Model T only comes in black, the color descriptions for the Fusion and Contour are not available in the dddw and the color ID is displayed instead.
There are a couple ways to deal with this. The first way I learned is described here The Ol’ Hidden Item in the dddw Part I. But I much prefer a technique I learned a long time ago in a PBDJ article written by a fellow named Ido Millet. I have hung onto this article and over the years have handed out many copies to colleagues.
Millet’s solution is to make a second copy of the Color column and have this always contain all the rows in its dddw. This second column is never filtered.
When the row is not the current row, display the column with the unfiltered dddw and hide the filter column. If the row is the current row, show the column with the filtered dddw, and hide the column with the dddw with all the possible rows. To do this, add the following expression to the visibility attribute of the column with the dddw which gets filtered:
IF (CurrentRow() = GetRow(), 1, 0)
The column with the dddw which always contains all the values will have the following expression in its visibility attribute:
IF (CurrentRow() = GetRow(), 0, 1)
The result is:
Now place this new column right on top of the column with the dddw which will get filtered.
One potential problem occurs when the user clicks on a different row and directly on the column. To ensure that the visibility expressions works correctly, add the following script to the Clicked event of the datawindow:
if row > 0 then this.ScrollToRow(row)
That is all there is to it. Isn’t this a lot easier than messing around with setting the detail height, and dddw events?
8 Comments »
Leave a Reply
- 1. PowerBuilder General
- 2. Datawindows
- 3. PFC