請教各位大俠,我想用treeview展現一個公司的層級,比如根節點是總公司,總公司下面有許多分公司,分公司下面有許多部門,部門下面又有小組,暫時就這4級層次。請問怎么實作?
因本人很久沒用過pb了,忘得也差不多了,麻煩能不能提供一個稍微詳細點demo,謝謝各位了。
uj5u.com熱心網友回復:
【構造事件】treeviewitem ltvi
long ll_handle
ltvi.PictureIndex = 2
ltvi.SelectedPictureIndex = 1
ltvi.Selected = False
ltvi.Children = True
ltvi.Data = '%'
ltvi.Label = "總公司"
ll_handle = tv_1.InsertItemLast(0,ltvi)
tv_1.ExpandItem(ll_handle)
【itempopulate事件】
treeviewitem ltvi,ltvi_parent
If tv_1.GetItem(Handle,ltvi_parent) <> 1 Then Return
DECLARE c1 CURSOR FOR SELECT item_class,class_name,class_data
FROM t_item_class WHERE item_class LIKE :ls_like
AND item_class <> :ls_no ORDER BY 1;
OPEN c1;
Do
FETCH c1 INTO :ls_no,:ls_name,:ls_three;
If sqlca.SQLCode <> 0 Then Exit
If gvar.grant_clsno <> "" Then
If PosA(gvar.grant_clsno,"'" + ls_no + "'") = 0 Then Continue
End If
ls_name = gm.pub_f_str2str(ls_name)
ls_three = gm.pub_f_str2str(ls_three)
ltvi.Data = ls_no
ls_name = ls_no + "." +ls_name
If ls_three <> "" And ls_three <> ls_no Then ls_name += "(" + ls_three + ")"
ltvi.Label = ls_name
ltvi.children = wf_have_child("cls", ls_no)
tv_1.InsertItemLast(Handle,ltvi)
lb_have_child = True
Loop While True
CLOSE c1 ;
從程式抄的一點代碼,自己研究一下吧
uj5u.com熱心網友回復:
【itempopulate事件】是首次展開,就在這里加載各個層次。uj5u.com熱心網友回復:
PB中treeview樹形視圖代碼事例Open事件代碼:
treeviewitem ltvi_data //定義一個樹形視圖變數
datastore lds_place //定義第一個資料存盤
int i,li_num_place
long handle
lds_place=create datastore //將資料存盤與資料視窗物件關聯
lds_place.dataobject="d_bm"
lds_place.settransobject(sqlca)
li_num_place=lds_place.retrieve( ) //檢索資料
for i=1 to li_num_place //回圈插入第一層節點資料
ltvi_data.label=lds_place.getitemstring(i,"bm") //為樹形視圖示簽賦值
ltvi_data.data=https://bbs.csdn.net/topics/lds_place.getitemstring(i,"bm1") //為樹形視圖DATA變數(ANY型別)定義一個想保存的資料
ltvi_data.pictureindex=1 //定義圖片索引
ltvi_data.selectedpictureindex=2 //定義選中圖示
ltvi_data.children=true //指定該節點仍有下級孩子節點
handle=tv_1.insertitemlast( 0, ltvi_data) //插入節點
next
destroy lds_place //釋放定義的資料存盤
===========================
ItemPopulate事件代碼:
treeviewitem ltvi_data,ltvi_place
datastore lds_person //定義第二個資料存盤
int j,li_num_person
long handle1
if this.getitem( handle,ltvi_place)=-1 then return //如果檢索資料不成功回傳-1
lds_person=create datastore //為資料存盤賦值
lds_person.dataobject="d_bm1" //為資料存盤連接第二個資料視窗物件,該物件需要使用SQL SELECT作為資料源并且定義一個檢索引數
lds_person.settransobject( sqlca)
li_num_person=lds_person.retrieve(ltvi_place.data) //用該節點的DATA值作為引數傳遞給第二個資料視窗物件
for j=1 to li_num_person //回圈插入第二層節點
ltvi_data.label=lds_person.getitemstring(j,"name")
ltvi_data.pictureindex=3
ltvi_data.selectedpictureindex=4
ltvi_data.children=false
handle1=tv_1.insertitemlast( handle,ltvi_data)
next
destroy lds_person //釋放資料存盤
uj5u.com熱心網友回復:
可以參考鏈接http://blog.sina.com.cn/s/blog_4640dfa501000awf.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/44780.html
標籤:基礎類
下一篇:pb datawindow保存卡
