PB中treeview 的checkboxes用法完整版

來源:互聯網
上載者:User

實現:treeview的同步選擇(checkboxes)的用法

         1、當選擇了父節點時,所有的子節點都已選擇

         2、當一個子節點未選擇時,父節點可以選擇

     本人總結了各方神人給出的checkboxes用法代碼,不是為了居功,只是給各位多提供一條搜尋路徑。參考來自CSDN

代碼:

1、為TreeView 添加一個使用者事件 ue_synchronizechildren(long handle, integer state),代碼如下:

long childitem

treeviewitem tvitem

getitem(handle, tvitem)

tvitem.statepictureindex=state

setitem(handle, tvitem)

childitem=this.finditem(ChildTreeItem!, handle)

do while(childitem<>-1)

this.Event ue_synchronizechildren(childitem, state) //遞迴遍曆後代結點

childitem=this.finditem(NextTreeItem!, childitem)

loop

2、為 treeview 添加使用者事件 ue_synchronizeparent(long handle, integer state),如下:

long parentitem

treeviewitem tvitem

getitem(handle, tvitem)

tvitem.statepictureindex=state

setitem(handle, tvitem)

parentitem=this.finditem(ParentTreeItem!, handle)

if parentitem<>-1 then

this.Event ue_synchronizeparent(parentitem, state)

end if

3、為 treeview 添加一個使用者事件 ue_statechanged(long handle, integer prevstate)檢測節點的選擇狀態, 如果發生了變化則調用ue_synchronizechildren同步後代節點,並根據需要通過ue_synchronizeparent同步祖先節點。代碼如下:

treeviewitem tvitem

getitem(handle, tvitem)

if tvitem.statepictureindex=prevstate then

return

else

this.Event ue_synchronizechildren(handle, tvitem.statepictureindex)

if tvitem.statepictureindex=1 then

long nextitem
treeviewitem ntvitem

nextitem=this.finditem(nexttreeItem!, handle) //同層下一項
do while(nextitem<>-1)
getitem(handle, ntvitem)
if ntvitem.statepictureindex=1 then return //有沒選中,就返回!
nextitem=this.finditem(NextTreeItem!, nextitem)
loop

nextitem=this.finditem(previoustreeItem!, handle) //同層上一項
do while(nextitem<>-1)
getitem(handle, ntvitem)
if ntvitem.statepictureindex=1 then return //有沒選中,就返回!
nextitem=this.finditem(previoustreeItem!,nextitem)
loop

this.Event ue_synchronizeparent(handle, tvitem.statepictureindex)
end if
end if

4、在 treeview 的clicked 事件裡寫入

treeviewitem tvitem

getitem(handle, tvitem)

post event ue_statechanged(handle, tvitem.statepictureindex)

完成上面四步即可完整滿足使用者要求,只需將代碼粘入即可,下面為貼圖


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.