How to Get the Display Value of a DDDW or DDLB Column
There are times when you want to get the display value of a dddw or ddlb. Most people try using gettext() after getting the dw child handle. That approach, however, does not work. Here are two methods that do work. LookupDisplay() is also useful in sort and filter dialog windows.
Solution #1 (Recommended):
Take advantage of the Describe() Evaluate function. In the following example the ddlb or dddw column is called state_code.
rownumber = string(dw_1.getrow())
displayvalue = dw_1.describe("Evaluate( 'lookupdisplay(state_code) ', "+rownumber+" )")
This solution does not require the definition of an additional computed column on the datawindow. Note: This solution will not work in the itemchanged event of the main datawindow. It must be done in an event that occurs After the itemchanged event has completed by creating a custom user event ON THE WINDOW mapped to pbm_customxx called getdisplayvalue and then windowname.postevent (getdisplayvalue) from the itemchanged event of the datawindow.
If you have several dddw columns or other columns, you may want to use a choose case statement to have an action associated with each column name.
CHOOSE CASE dw_1.getcolumnname()
displayvalue = dw_1.describe("Evaluate( 'lookupdisplay(state_code) ', +rownumber+" )")
displayvalue = dw_1.describe("Evaluate( 'lookupdisplay(city_code) ', "+rownumber+" )")
Solution #2 (Computed Column Approach):
1. Go into the Datawindow painter and add a computed column. The expression should be: Lookupdisplay(dept_id) where dept_id is the name of your ddlb or dddw column. Name the computed column 'display'. Place the computed column anywhere since we will make it invisible with Modify().
2. Go into the window and add a user event called ue_lookup. In the script for this event code:
// displayvalue will contain the display value the user has selected from ddlb or dddw column
displayvalue = dw_1.getitemstring(dw_1.getrow(),"display")
In the Itemchanged event for the main DataWindow (dw_1) code:
// check to see if the ddlb or dddw column is the correct one they are changing.
// use the column number (#) of the ddlb or dddw column.
if getcolumn() = 3 then
parent.event post ue_lookup()
In the open event for the window add:
(This sets the computed columns visible attribute to "invisible".)