pb数据窗口数据输入的下拉选择效果

1.建立子数据窗口.

2.在dw_1.editchanged中写如类似下面代码

if row <=0 then return
DataWindowChild state_child
accepttext( )
string ls_value,partname,cartype
long findIndex
if dwo.name = "partno" then
 GetChild("partno", state_child)
 state_child.accepttext( )
 ls_value = trim(getitemstring(row,"partno"))
 state_child.SetTransObject(SQLCA)
 state_child.Retrieve()
 state_child.setfilter( "p_partno like '%"+ls_value+"%' ")
 state_child.filter( )

 end if

3.在dw_1.itemchanged中写如下代码

dw_1.event itemfocuschanged( row, dwo)

因为acceptText()会触犯,itemchanged事件,所以不能在itemchanged事件中写acceptText()

4.在itemfocuschanged中写如下代码

if row <=0 then return

if dwo.name="partno" then
 accepttext( )
 string partno,partname,cartype
 partno = trim(dw_1.getitemstring(row,"partno"));
 
 select p_partname,p_yw into:partname,:cartype from p_partno
 where p_partno=:partno;
 commit;
 
 dw_1.setitem( row, "partname", partname);
 dw_1.setitem( row, "cartype", cartype);
 accepttext( )
end if

5.回车键代替Tab件,需要给dw_1建立个用户自定义事件

6.将使用setitem设置的列tab设置成0

*********************改进措施*****************************

申明窗体变量partno_ds
在open事件中填充partno_ds

string cmdText
cmdText="SELECT p_partno Partno,p_partName PartName,p_yw CarType " + &
               " from p_partno where (p_partno <> '' AND  p_partno is not null and p_partno >'-') " + &
               " order by  p_partno";

partno_ds= gf_fill_ds(cmdText);
调整editchanged事件代码为使用sharedata方式
if row <=0 then return
DataWindowChild state_child
accepttext( )
string ls_value;
long findIndex
if dwo.name = "partno" then
 GetChild("partno", state_child)
 state_child.accepttext( )
 ls_value = trim(getitemstring(row,"partno"))
 partno_ds.sharedata( state_child)
    if  not isnull(ls_value) and trim( ls_value) <> '' then
   state_child.setfilter( "partno like '%"+ls_value+"%' ")
    else
   state_child.setfilter("")
    end if
 state_child.filter( );
  end if
调整itemfocuschange事件为datastore查找

if row <=0 then return

if dwo.name="partno" then
 accepttext( )
 long findIndex
 string partno,partname,cartype
 partno = trim(dw_1.getitemstring(row,"partno"));
 
  findIndex=partno_ds.find( "partno='"+ partno+"'",1, partno_ds.rowcount( ) );
  if(findIndex>=1 ) then
     partname=partno_ds.getitemstring( findIndex,"partname")
   cartype=partno_ds.getitemstring( findIndex, "cartype")
   dw_1.setitem( row, "partname", partname);
     dw_1.setitem( row, "cartype", cartype);
  accepttext( )
     end if

end if

原文地址:https://www.cnblogs.com/wdfrog/p/2239390.html