PB实现TreeView多级分类检索(案例)

contructor事件:

long ll_row,i
TreeViewItem tv_new

 //建立一个图标队列,供其中的TreeViewItem项引用,在这里建立主要是为了能够控制图标大小 //首先设定图标显示尺寸
This.PictureHeight=16
This.PictureWidth=16 //图标队列由4个图标构成,前3个用于标识医嘱类项目的级别,第4个用于标识项目的选中状态
This.AddPicture("DosEdit5! ")
This.AddPicture("custom023!")
This.AddPicture("custom036!")
This.AddPicture("Custom050!")


DataStore lds_dw  //定义为实例变量
lds_dw = Create DataStore
lds_dw.DataObject = 'dw_assets_directory'
lds_dw.SetTransObject( Sqlca )


lds_dw.SetFilter( "ass_uplevel = 0")
lds_dw.Filter()
lds_dw.ReTrieve()
ll_row = lds_dw.RowCount()


for i = 1 to ll_row
    tv_New.Label=lds_dw.GetItemString(i,'ass_name')
    tv_New.Data=lds_dw.GetItemNumber(i,'ass_no')
    tv_New.level = 1
    tv_New.PictureIndex=1
    tv_New.SelectedPictureIndex=4
    tv_New.Children=True
    This.InsertItemLast(0, tv_New)
next
Destroy lds_dw

Itempopulate事件:

long Level, n, i
any Parm1, Parm2, Parm3
Long ll_Parent
TreeViewItem tv_Current, tv_Parent, tv_New
//由句柄获得TreeViewItem项,存入变量tv_Current
GetItem(handle, tv_Current)
Level=tv_Current.Level+1
tv_New.PictureIndex=Level
tv_New.SelectedPictureIndex= 4 //自己设计图片此处可以等于Level
//根据展开级别,建立当前展开项目

DataStore lds_dw  //定义为实例变量
lds_dw = Create DataStore
lds_dw.DataObject = 'dw_assets_directory'
lds_dw.SetTransObject( Sqlca )

CHOOSE CASE Level
    CASE 2
        //展开第2级医嘱类项目
        tv_New.Children=True
        Parm1= tv_Current.Data
        //通过ds_yzzl检索当前项目类所具有的医嘱种类

        lds_dw.SetFilter( "ass_uplevel = " + String(Parm1) )
        lds_dw.Filter()
        lds_dw.ReTrieve()
        n = lds_dw.RowCount()

        //依次到ds_yzzl中提取医嘱种类,建立该项目
        FOR i=1 TO n
            //取ds_yzzl中zl字段的显示内容和内部值,
            //作为这里对应项的显示文字和内部值
            tv_New.Label = lds_dw.GetItemString(i,'ass_name')
            //tv_New.Label = lds_dw.Describe("evaluate('lookupdisplay(ass_name)',"+ string(i)+")")
            tv_New.Data = lds_dw.GetItemNumber(i, 'ass_no')
            tv_New.level = Level
            This.InsertItemLast(handle, tv_New)
        NEXT
        lds_dw.SetFilter( '1 = 2' )
        lds_dw.Filter()
    CASE 3
        //展开第3级医嘱类项目
        tv_New.Children=True
        //由句柄获取其父项的句柄
        ll_Parent=FindItem(ParentTreeItem!,handle)
        GetItem(ll_Parent, tv_Parent)
        Parm1=tv_Parent.Data
        Parm2=tv_Current.Data
        //通过ds_yzjtlx检索当前医嘱类所具有的具体医嘱类型
        lds_dw.SetFilter( "ass_uplevel = " + String(Parm2) )
        lds_dw.Filter()
        lds_dw.ReTrieve()
        n = lds_dw.RowCount()

            //依次到ds_yzjtlx中提取具体医嘱类型,建立该项目
            FOR i=1 TO n
                tv_New.Label = lds_dw.GetItemString(i,'ass_name')
                //tv_New.Label = lds_dw.Describe("evaluate('lookupdisplay(ass_name)'," + string(i)+")")
                tv_New.Data = lds_dw.GetItemNumber(i,'ass_no')
                tv_New.level = Level
                This.InsertItemLast(handle, tv_New)
            NEXT
        lds_dw.SetFilter( '1 = 2' )
        lds_dw.Filter()
    CASE 4
        //展开第4级医嘱类项目
        tv_New.Children=false
        //由句柄获取其父项的句柄
        ll_Parent=FindItem(ParentTreeItem!,handle)
        GetItem(ll_Parent, tv_Parent)
        Parm1=tv_Parent.Data
        Parm2=tv_Current.Data
        Parm3=tv_Current.Data
        //通过ds_yzjtlx检索当前医嘱类所具有的具体医嘱类型
        lds_dw.SetFilter( "ass_uplevel = " + String(Parm3) )
        lds_dw.Filter()
        lds_dw.ReTrieve()
        n = lds_dw.RowCount()

            //依次到ds_yzjtlx中提取具体医嘱类型,建立该项目
            FOR i=1 TO n
                tv_New.Label = lds_dw.GetItemString(i,'ass_name')
                //tv_New.Label = lds_dw.Describe("evaluate('lookupdisplay(ass_name)'," + string(i)+")")
                tv_New.Data = lds_dw.GetItemNumber(i,'ass_no')
                tv_New.level = Level
                This.InsertItemLast(handle, tv_New)
            NEXT
        lds_dw.SetFilter( '1 = 2' )
        lds_dw.Filter()     
END CHOOSE
Destroy lds_dw

selectionchanged事件:

integer Level
any Parm1,Parm2,Parm3 //string Parm1, Parm2, Parm3
long ll_Parent
TreeViewItem tv_Current, tv_Parent
GetItem(newhandle, tv_Current)
Level = tv_Current.Level
Parm1 = tv_Current.data //判断当前项目是否为第3级医嘱类, //如是让旁边的DataWindow列出实施该项医嘱的病人清单 //否则,将其置空。
dw_1.setfilter("1=2" )
dw_1.filter()
choose case level
    case 1
        dw_1.setfilter("ass_uplevel =" + string(Parm1) )
    case 2
        dw_1.setfilter("ass_uplevel =" + string(Parm1) )
    case 3
        dw_1.setfilter("ass_uplevel =" + string(Parm1) )
    case 4
        //dw_1.setfilter("ass_uplevel =" + string(Parm1) )
        dw_1.setfilter("ass_no =" + string(Parm1) )
end choose
dw_1.filter()
dw_1.retrieve()

clicked事件:

//数据点击事件在selectionchanged事件后发生
//点击一次为所有子项,再点击一次为本身属性

any la_dtcode

String ls_dtname,ls_tempfilter,ls_tabsql
treeviewitem ltvi_1
this.getitem(handle,ltvi_1)

ls_dtname = ltvi_1.label
la_dtcode = ltvi_1.data
dw_1.setfilter("ass_no =" + string(la_dtcode) )

dw_1.filter()
dw_1.retrieve()

你可能感兴趣的:(treeview)