2008年12月29日星期一

也谈“PB中相关联下拉数据窗口的实现”(jqz1225原创)

“PB中相关联下拉数据窗口的实现”中的原文:许多资料称设置检索参数是最简单、最方便的有效解决方法,也提出了几种隐藏系统自动弹出的“Specify Retrieval”对话框的方法。但令人遗憾的是本人竭尽所能也未能如愿(主要是无法隐藏系统自动弹出的“Specify Retrieval”对话框)。

看了之后,觉得怎么可能,我是个pb的初学者,但我也不相信无法隐藏统自动弹出的“Specify Retrieval”对话框,于是用原文章的三张表试了试。

一、建立datawindow

1) d_dept:

SELECT "dept"."dept_id", "dept"."dept_name" FROM "dept"

2) d_unit:

SELECT "unit"."unit_id",
"unit"."unit_name",
"unit"."dept_id"
FROM "unit"
WHERE "unit"."dept_id" = :as_dept_id
此数据窗口使用了retrieval argument: "as_dept_id"


3) d_feedata:

SELECT "feedata"."dept_id",
"feedata"."unit_id",
"feedata"."num"
FROM "feedata"

此数据窗口的

dept_id字段:Edit Style: Dropdown datawindow, 对应的datawindow为d_dept

unit_id字段:Edit Style: Dropdown datawindow, 对应的datawindow为d_unit, 其AutoRetrieve设为False

二、建立窗口w_main

1. w_main的open事件:

datawindowchild child_dept, child_unit

dw_1.settransobject(sqlca)
dw_1.retrieve()
//
if dw_1.getchild( ''''dept_id'''', child_dept)<0 then
messagebox(''''警告'''',''''数据字典有误'''')
close(this)
return
end if

child_dept.settransobject(sqlca)
child_dept.retrieve()
//
if dw_1.getchild( ''''unit_id'''', child_unit)<0 then
messagebox(''''警告'''',''''数据字典有误'''')
close(this)
return
end if

child_unit.settransobject(sqlca)

// child_unit.retrieve() //此句不能写,否则retrieval argument窗口就出来了

2. dw_1的itemchanged事件:

datawindowchild child_unit

if dwo.name = ''''dept_id'''' then //dept_id字段的值发生改变
if dw_1.getchild( ''''unit_id'''', child_unit)< 0 then
messagebox(''''警告'''',''''数据字典有误'''')
return
end if
child_unit.retrieve(data) // data即为dept_id当前的值,此时才带参数值调用retrieve
end if


三、结论

上文中用黑体标出的三个地方是关键。

来源转载: http://www.host01.com/article/software/PowerBuilder/20060918005202866.htm

没有评论: