Schultz’s PowerBuilder Notes

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?


November 16, 2008 - Posted by | Drop Down Data Window (DDDW) | , , , , , , , , , , ,


  1. Very interesting method.
    I have myself been using the SetDetailHeight approach, with the annoyances you have referred to.

    However I fail to understand how this will work in a grid (processing=1), since a data column will require a display column and you can’t have them on the same position, like in tabular. Of cause you can fake it and make a grid look-alike, like in your example, but then there are other tradeoffs, like column resizing etc.

    Comment by Thomas Waldorff | December 10, 2008 | Reply

  2. Thomas, you are right, this will not work for a grid view. Thanks for pointing out my oversight, I have edited the post.

    Comment by rick130 | December 10, 2008 | Reply

  3. This is GOOD and easier to code…

    Thank You!

    Comment by Jeff Trout | February 21, 2009 | Reply

  4. […] way to achieve this result is to borrow the technique discribed in the post The Ol’ Hidden Items in the dddw Part II.  This method also deals with tabular datawindow styles where multiple rows are displayed and the […]

    Pingback by Making DW Radio Buttons and Check Boxes look disabled « Schultz’s PowerBuilder Notes | March 17, 2009 | Reply

  5. This was EXTREMELY helpful!!! Thank you!! Frustrating that PB make you jump through so many hoops, I’m sure if there was more support for dynamic DDDWs, people would love that.

    Comment by Len | March 25, 2011 | Reply

  6. Thanks, this was very helpful.
    I had tried a method setting and removing filtering with no success.
    This was very simle, and it worked.
    The only thing I missed was an explanation for the visible attribute.
    I had never used it before, so it delayed me a minut or two.

    Comment by Christian | October 19, 2011 | Reply

  7. can you please help me code if i have 4 dddw. my first dddw contains region. 2nd dddw is province, 3rd dddw is municipality and last dddw is barangays. if i choose the region name on my 1st dddw, the 2nd dddw shows provinces on that regions, then on the ill choose a province, the 3rd dddw shows all the municipalities on that particular province and when i choose a certain municipality on my 3rd dddw. on the 4th dddw shows all barangays on that particular municipality.
    my dddw are all on a dw. thanks


    Comment by joseph | May 23, 2012 | Reply

    • This technique described will work for your issue you described. Sorry, can’t give you the code as I do not work for your :) Suggest writing this for the first two dddw and once this is complete introduce the the third dddw. With a little thought and work you should get this going. Once this is working right, introduce the last dddw.

      Good Luck!

      Comment by rick130 | May 23, 2012 | Reply

  8. I having same issue but when i tried the solution provided its not working.I added a duplicate column same as mentioned above to add COLOR column and set the visible property and clicked event script. But still the duplicated column is showing the data value instead of display value. If I am missing something kindly guide.

    Comment by abhishek | August 19, 2014 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: