PB 控件DropDownListBox绑定下拉菜单项的方法(pbm_constructor)-游标
DropDownListBox下拉框值添加
PB开发中难免会用到DropDownListBox,其下拉选项可以通过Items属性编辑,也可以通过语句ddlb_1.AddItem("选项值")添加,如下图与代码:
ddlb_1.AddItem("选项值一") ddlb_1.AddItem("选项值二") ddlb_1.AddItem("选项值三")
通过上述方法可以实现下拉选项值的添加,程序编译以后后期如何动态添加呢?
方法如下:
一、编辑控件事件pbm_constructor
STRING code,name DECLARE WARD CURSOR FOR SELECT "DEPT_DICT"."DEPT_CODE", "DEPT_DICT"."DEPT_NAME" FROM "DEPT_DICT" WHERE ( "DEPT_DICT"."OUTP_OR_INP" = 1 ) AND ( "DEPT_DICT"."CLINIC_ATTR" = 2 ) ORDER BY "DEPT_DICT"."sort"; OPEN WARD; FETCH WARD INTO :code,:name; DO WHILE SQLCA.sqlcode=0 AddItem(name) FETCH WARD INTO :code,:name; LOOP CLOSE WARD;
二、代码解释
2.1创建游标
DECLARE WARD CURSOR FOR //创建游标 查询语句; OPEN WARD; //打开游标 FETCH WARD INTO :code,:name; //循环游标值 DO WHILE SQLCA.sqlcode=0 //判断获取数据是否成功,不成功则不执行 AddItem(name) //添加下拉项值 FETCH WARD INTO :code,:name; //继续循环取值 LOOP CLOSE WARD; //关闭游标
2.2结果
三、预留方法
DropDownListBox
int selno
selno = ddlb_deptname.finditem(ddlb_deptname.text,1)
messagebox("",string(selno))