侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

PB树形控件勾选联动

2023-11-08 星期三 / 0 评论 / 0 点赞 / 53 阅读 / 4137 字

//因为CSDN登陆需要绑定手机,所以将原来的blog内容迁徙至这里 做PB树形控件的时候需要勾选联动,从网上找了个方案,但是对向上勾选支持的不是很好,自己做了点优化,希望可以帮到别人 首先treev

//因为CSDN登陆需要绑定手机,所以将原来的blog内容迁徙至这里

做PB树形控件的时候需要勾选联动,从网上找了个方案,但是对向上勾选支持的不是很好,自己做了点优化,希望可以帮到别人

首先treeview需要勾选 checkboxes属性

在tv_1.clicked事件中增加代码

TreeViewItem ltvitem
getitem(handle, ltvitem)

post event ue_statechanged(handle, ltvitem.statepictureindex)

在树形控件中新增函数 ue_statechanged(long handle,integer prevstate)   代码如下

treeviewitem ltvi_item
getitem(handle, ltvi_item)

if ltvi_item.statepictureindex = prevstate then
    return
else
    this.Event ue_synchronizechildren(handle,ltvi_item.statepictureindex)    //这个函数包含了向下的选中和取消
    this.Event ue_synchronizeparent(handle,ltvi_item.statepictureindex)       //优化了这个函数
end if

在树形控件新增函数 ue_synchronizechildren(long handle,integer state) 代码如下

long ll_childitem
treeviewitem ltvi_item
getitem(handle, ltvi_item)
ltvi_item.statepictureindex = state
setitem(handle, ltvi_item)
ll_childitem = this.finditem(ChildTreeItem!, handle)
do while(ll_childitem <> -1)
    this.Event ue_synchronizechildren(ll_childitem, state) //递归遍历后代结点
    ll_childitem = this.finditem(NextTreeItem!, ll_childitem)
loop

在树形控件新增函数 ue_synchronizeparent(long handle,integer state) 代码如下

long ll_parentitem,ll_nextitem
treeviewitem ltvi_item,ltvi_nextitem
this.getitem(handle, ltvi_item)
ltvi_item.statepictureindex = state
this.setitem(handle, ltvi_item)
if state = 1 then
    ll_parentitem = this.finditem(ParentTreeItem!, handle)
    if ll_parentitem > 0 then
        this.getitem(ll_parentitem, ltvi_item)
        ltvi_item.statepictureindex = state
        this.Event ue_synchronizeparent(ll_parentitem, state)
    else
        return
    end if
else
    ll_nextitem = this.finditem(NextTreeItem!, handle) //同层下一项
    do while(ll_nextitem <> -1)
        getitem(ll_nextitem, ltvi_nextitem)
        if ltvi_nextitem.statepictureindex = 1 then return //有没选中,就返回!
        ll_nextitem = this.finditem(NextTreeItem!, ll_nextitem)
    loop
    ll_nextitem = this.finditem(previoustreeItem!, handle) //同层上一项
    do while(ll_nextitem <> -1)
        getitem(ll_nextitem, ltvi_nextitem)
        if ltvi_nextitem.statepictureindex = 1 then return //有没选中,就返回!
        ll_nextitem = this.finditem(previoustreeItem!,ll_nextitem)
    loop
    ll_parentitem = this.finditem(ParentTreeItem!, handle)
    if ll_parentitem > 0 then
        this.getitem(ll_parentitem, ltvi_item)
        ltvi_item.statepictureindex = state
        this.Event ue_synchronizeparent(ll_parentitem, state)
    else
        return
    end if
end if
this.Event ue_synchronizeparent(ll_parentitem,state)

 

这样这个树形控件可以更完美的实现勾选功能,代码基于前辈代码做的优化,具体出处现在找不到了,感谢

广告 广告

评论区