PB 树形构造
本帖最后由 u011513236 于 2013-09-08 14:24:39 编辑 想做一个关于商品种类的树形
该表包含了 ID(编号)、NAME(名称)、PATENTID(父节点)、LEVEL(层数)4个列
该怎样建立一个树形,能够通过右键增删改
是先创建datawindow——treeview还是直接先在窗口插入treeview,然后通过代码来完成创建、删除、修改。以及按照level来进行排序
如果不是应该怎么做,求高手指导 treeview
[解决办法]
在window上面摆上一个 TreeView
做个加载函数,(函数里面进行递归调用)
给个例子你,我写的根据用户ID,显示用户权限功能的树
public subroutine
wf_create_tree (integer al_userid, integer al_handle);//================================
//===功能:刷新树 ===
//===参数:al_userid 用户ID ===
//=== al_handle 节点句柄 ===
//================================
long i, ll_count //DS的记录行数
long ll_functionid //功能ID
long ll_handle_new //新节点句柄
long ll_picture_count //树形控件的图片总量
string ls_img //节点图片
long ll_temp
datastore ds_tree //数据源
treeviewitem ltvi_new ,ltvi_item //新节点,当前节点
//删除图片
ll_picture_count = upperbound(tv_rights.picturename[])
for i=1 to ll_picture_count
tv_rights.deletepicture( i )
next
ds_tree = create datastore
ds_tree.dataobject = 'd_set_userright_tree'
ds_tree.settransobject(sqlca)
//通过句柄获取当前节点data值(功能ID)
if al_handle > 0 then
tv_rights.getitem(al_handle, ltvi_item)
ll_functionid = long(ltvi_item.data)
else
ll_functionid = 0
end if
//刷新DS
ll_count = ds_tree.retrieve(al_userid,ll_functionid)
//循环,插入子节点
for i=1 to ll_count
ltvi_new.label = ds_tree.getitemstring(i,'name')
ltvi_new.data = ds_tree.getitemnumber(i,'id')
ls_img = ds_tree.getitemstring(i,'img')
if (isnull(ls_img) or trim(ls_img) = '') = false then
ll_temp = tv_rights.addpicture( ls_img)
ltvi_new.pictureindex = ll_temp
ltvi_new.selectedpictureindex = ll_temp
else
ltvi_new.pictureindex = 0
ltvi_new.selectedpictureindex = 0
end if
if ds_tree.getitemstring(i,'right') = 'Y' then
ltvi_new.statepictureindex = 2
else
ltvi_new.statepictureindex = 1
end if
ll_handle_new = tv_rights.insertitemlast( al_handle,ltvi_new )
wf_create_tree(al_userid,ll_handle_new)
next
//如果存在子节点,则更新当前节点
if al_handle > 0 and ll_count > 0 then
if ltvi_item.children = false then
ltvi_item.children = true
tv_rights.setitem(al_handle,ltvi_item)
end if
end if
destroy ds_tree
end subroutine