DDDW Contents Based on the Value of Another Column
The Problem
The contents of a particular drop down datawindow (dddw) depends on the value of another column. In the example, Version No is a drop down data window whose contents depend on the value of Tool Name. Version No will be a dddw child. Many books use retrieval arguments, but Andy Kempen showed me a way of using filter to avoid the additional database traffic. Note, this example assumes that the Code Value and the Display Value of the DDDW are the same. If they are different you will have another problem which will be addressed in another post
- When the datawindow is retrieved, the entire contents of the dddw child must also be retrieved. In the ue_retrieve event:
// override ancestor
datawindowchild dwc
string ls_tool_name
this.GetChild("version_no", dwc)
dwc.SetTransObject(SQLCA)
dwc.Retrieve( )
this.SetTransObject(SQLCA)
IF this.Retrieve(il_uo_seq_no) < 0 THEN
IF SQLCA.SQLCode < 0 THEN
MessageBox("[1]uo_dw@ue_retrieve", SQLCA.SQLErrText, stopsign!)
END IF
END IF
IF This.GetRow( ) = 0 THEN
this.Event ue_insert( )
END IF
- If the user selects a different row, the column which drives the DDDW child may change, so the contents of the DDDW child will have to be updated. In the RowFocusChanged event:
datawindowchild dwc
string ls_tool_name
this.GetChild("version_no", dwc)
ls_tool_name = this.GetItemString ( currentrow, "tool_name" )
IF IsNull(ls_tool_name) THEN
ls_tool_name = ""
END IF
dwc.SetFilter("tool_name = '" + ls_tool_name + "'" )
dwc.Filter( )
If the column which drives the DDDW child changes, the contents of the DDDW child will also have to change. So in the ItemChanged event:
datawindowchild dwc
string ls_tool_name,ls_null
IsNull(ls_null)
IF Upper(getcolumnname( )) = "TOOL_NAME" THEN
this.GetChild("version_no", dwc)
ls_tool_name = data
dwc.SetFilter("tool_name = '" + ls_tool_name +"'" )
dwc.Filter( )
SetItem(row, "version_no", ls_null)
end if
- If a new row is inserted, the dwc should not have any rows as the tool_name column is empty. Script in the ue_insert event:
datawindowchild dwc
decimal ld_seq_num
integer li_rc
string ls_tool_name, ls_null
ld_seq_num = il_uo_seq_no
li_rc = this.SetItem ( this.GetRow( ), "SEQ_NO" , ld_seq_num )
IsNull(ls_null)
IF Upper(getcolumnname( )) = "TOOL_NAME" THEN
this.GetChild("version_no", dwc)
dwc.SetFilter("tool_name = '" + ls_null + "'" )
dwc.Filter( )
END IF
1 Comment »
Leave a comment
-
Archives
- May 2009 (1)
- March 2009 (1)
- January 2009 (2)
- December 2008 (1)
- November 2008 (2)
- September 2008 (1)
- August 2008 (1)
- July 2008 (24)
- June 2008 (22)
- May 2008 (69)
- April 2008 (25)
-
Categories
-
RSS
Entries RSS
Comments RSS
[...] 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 or grid view, problems may soon [...]
Pingback by The Ol’ Hidden Items in the Dddw Problem Part II « Schultz’s PowerBuilder Notes | December 1, 2008 |