高手指教@!!!怎样利用treeview把一张3级的表显示

lgstal 2003-08-23 01:21:49
我现在要做一个treeview,将一张有1,2,3种级别的商品表作成形如windows里文件分级.
大类里有小类时用"+"号显示.
高手指教!!
...全文
47 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
runsoft 2003-08-26
  • 打赏
  • 举报
回复
使用数据库来实现把
id,name,parent_id,parent_path,mem
这个数据结构实现N级别的树型很方便
chenguying 2003-08-26
  • 打赏
  • 举报
回复
我觉得还是用 datawindow 或 datastore 好一点
表结构 id,name,parentid,children
建一数据窗口,参数为 parentid(上级节点 id),如果卫第一级可设为 main
treeview 的 constructor 事件
treeviewitem ltvi_insert
long ll_root
dw_1.settransobject(sqlca)
dw_1.retrieve()
ltvi_insert.data = 'main'
ltvi_insert.label = 'ROOT'
ltvi_children = true
ll_root = this.insertitemlast(0,ltiv_insert)
this.expanditem(ll_root)

treeview 的 itempopulate 事件
treeviewitem ltvi_insert
long ll_row
string ls_children

getitem(handle,ltvi_insert)
dw_1.setfilter('parentid = ' + string(ltvi.data))
dw_1.filter()
for ll_row = 1 to dw_1.rowcount()
ltvi_insert.data = dw_1.getitemstring(ll_row,'id')
ltvi_insert.label = dw_1.getitemstring(ll_row,'name')
ls_children = dw_1.geitemstring(ll_row,'children')
if ls_children = '1' then
ltvi_insert.children = true
else
ltvi_insert.children = false
end if
insertitemlast(handle,ltvi_insert)
next
pengdesheng 2003-08-26
  • 打赏
  • 举报
回复
给个递归的给你,,

string ls_id,ls_leveid,ls_name,ls_filter
treeviewitem tv_temp
ulong lul_temp
/*
wf_refresh(treeview atv_list,string as_id,unsignedlong aul_handle,integer ai_count)
Auth Date
wqjk 2003-7-10

*/
long ll_rowcount,ll_row
datastore lds_temp
if aul_handle<0 then goto toerr

lds_temp = Create datastore
lds_temp.dataobject = 'd_type_list'
lds_temp.settransobject(sqlca)
ls_filter = fill('_',ai_count)
ll_rowcount = lds_temp.retrieve(as_id + '__')
if ll_rowcount<1 then goto toerr
for ll_row = 1 to ll_rowcount
ls_id = lds_temp.getitemstring(ll_row,'c_id')
ls_leveid = lds_temp.getitemstring(ll_row,'c_level')
ls_name = lds_temp.getitemstring(ll_row,'c_name')
tv_temp.data = ls_id
tv_temp.label = ls_name
lul_temp = atv_list.insertitemlast(aul_handle,tv_temp)
if lul_temp<0 then continue;
wf_refresh(atv_list,ls_leveid,lul_temp,ai_count)
next
destroy lds_temp
return lul_temp
toerr:
if isvalid(lds_temp) then destroy lds_temp
return -1
qyz 2003-08-23
  • 打赏
  • 举报
回复
在PB自带的实例代码里有用数据窗口和树显示硬盘目录结构的例子
lgstal 2003-08-23
  • 打赏
  • 举报
回复
多谢!!
mmjhcg 2003-08-23
  • 打赏
  • 举报
回复
我给一个程序:
long root_item
long new_item1,new_item2,new_item3
string temp_erea_name
long temp_erea_id
string temp_office_name
long temp_office_id
string temp_personel_name
long temp_personel_id
long temp_erea_number
long temp_office_number
long temp_personel_number
treeviewitem temp_tree

tv_1.setredraw(false)
tv_1.deleteitem( root_item)
temp_tree.label="员工分类"
temp_tree.pictureindex=1
temp_tree.selectedpictureindex=1
root_item=tv_1.insertitemlast(0,temp_tree)
dw_erea.settransobject(sqlca)
dw_erea.retrieve( )
dw_erea.setfilter( "personel_id=" + trim(string(personel_information.id)))
dw_erea.filter( )
for temp_erea_number=1 to dw_erea.rowcount( )
//显示地区
temp_erea_name=trim(dw_erea.getitemstring(temp_erea_number,"erea_name"))
temp_tree.label=temp_erea_name
temp_tree.pictureindex=1
temp_tree.selectedpictureindex=1
new_item1=tv_1.insertitemlast( root_item,temp_tree)
//显示办公室
dw_office.settransobject( sqlca)
dw_office.retrieve(temp_erea_name)
dw_office.setfilter( "personel_id=" + trim(string(personel_information.id)))
dw_office.filter( )
for temp_office_number=1 to dw_office.rowcount()
temp_office_name=trim(dw_office.getitemstring(temp_office_number,"office_name"))
temp_tree.label=temp_office_name
temp_tree.pictureindex=2
temp_tree.selectedpictureindex=2
new_item2=tv_1.insertitemlast(new_item1,temp_tree)
// //显示人员
dw_personel.settransobject( sqlca)
dw_personel.retrieve(temp_erea_name,temp_office_name)
dw_personel.setfilter( "personel_id=" + trim(string(personel_information.id)))
dw_personel.filter( )
for temp_personel_number=1 to dw_personel.rowcount()
temp_personel_name=trim(dw_personel.getitemstring( temp_personel_number,"name"))
temp_tree.label=temp_personel_name
temp_tree.pictureindex=3
temp_tree.selectedpictureindex=3
new_item3=tv_1.insertitemlast(new_item2,temp_tree)
next
next
next
tv_1.setredraw( true)
tv_1.expanditem( 1)
lgstal 2003-08-23
  • 打赏
  • 举报
回复
xiexie
jdsnhan 2003-08-23
  • 打赏
  • 举报
回复
如果数据量不大的话,可以用递归实现
如果数据量大,用dw或ds比较好。
方法和楼上的差不多,先插入根,然后插入第一级,
再以第一级为根插入与其对应的第二级,同理,插入第三级
zzutligang 2003-08-23
  • 打赏
  • 举报
回复
treeview控件当节点的children属性为true或则向该节点直接插入子节点的时候该节点前面自动有一个"+"。
另外,给你提供一个思路:
首先将第1级别的类别插入到根节点下,然后设置该节点的children属性为true.
在tree的节点展开事件中获得用户展开的节点,判断该节点是不是第一次展开,如果是就从数据库检索该节点的类别的子类别,用同样的方法插入该该节点的下面。
这样做可以避免如果你的数据很多的话,tree的初始化要消耗很长时间,窗口半天出不来的的问题。

1,072

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧