Treeview的乙個遞迴演算法

2021-04-13 02:09:15 字數 2766 閱讀 9797

option   explicit  

private   sub   form_load()  

with   treeview1  

.nodes.add   ,   ,   "parent1",   "test1"  

.nodes.add   "parent1",   tvwchild,   "child1",   "test_ch1"  

.nodes.add   "parent1",   tvwchild,   "child2",   "test_ch2"  

.nodes.add   "parent1",   tvwchild,   "child3",   "test_ch3"  

.nodes.add   "child3",   tvwchild,   "child_33",   "test_ch3_ch3"  

.nodes.add   "parent1",   tvwchild,   "child4",   "test_ch4"  

.nodes.add   "parent1",   tvwchild,   "parent2",   "test2"  

.nodes.add   "parent2",   tvwchild,   "child11",   "test_ch1"  

.nodes.add   "parent2",   tvwchild,   "child22",   "test_ch2"  

.nodes.add   "parent2",   tvwchild,   "child33",   "test_ch3"  

.nodes.add   "parent2",   tvwchild,   "child44",   "test_ch4"  

.checkboxes   =   true  

.linestyle   =   tvwtreelines  

end   with  

nodeallexpanded   treeview1  

end   sub  

private   sub   treeview1_nodecheck(byval   node   as   mscomctllib.node)  

call   allchildsynchro(node)  

call   allmatersynchro(node)  

end   sub  

'//   -選中下級-  

private   sub   allchildsynchro(byval   nodechoose   as   object)  

on   error   resume   next  

dim   lnextloop   as   long  

dim   objchildren   as   object  

if   cbool(nodechoose.children   >   0)   then  

set   objchildren   =   nodechoose.child  

for   lnextloop   =   1   to   nodechoose.children  

objchildren.checked   =   nodechoose.checked  

if   objchildren.children   >   0   then   call   allchildsynchro(objchildren)  

set   objchildren   =   objchildren.next  

next   lnextloop  

end   if  

end   sub  

'//   -取消上級-  

private   sub   allmatersynchro(byval   nodechoose   as   object)  

on   error   resume   next  

if   not   nodechoose.checked   then   if   typename(nodechoose.parent)   =   "inode"   then   nodechoose.parent.checked   =   false  

if   not   nodechoose.checked   then   if   typename(nodechoose.parent)   =   "inode"   then   call   allmatersynchro(nodechoose.parent)  

end   sub  

'//   -節點張開-  

private   sub   nodeallexpanded(byval   objtvw   as   object)  

on   error   resume   next  

dim   objchild   as   object  

for   each   objchild   in   objtvw.nodes  

objchild.expanded   =   iif(objchild.key   =   objchild.root.key,   false,   true)  

objchild.root.expanded   =   iif(objchild.key   =   objtvw.nodes(objtvw.nodes.count).key,   true,   false)  

next   objchild  

end   sub   

乙個遞迴演算法

要求實現1,1,2,3,5,8,13,21,這樣乙個序列。分析一下輸出結果 發現後乙個數字是前2個數字的和。遞迴演算法如下 public static int recursion int i if i 0 return 0 else if i 0 i 2 return 1 else return r...

TreeView 經典遞迴演算法

前台 無標題頁 title head body form id form1 runat server div asp treeview id treeview1 runat server asp treeview div form body html 後台 using system using sy...

乙個關於遞迴的演算法。

從鍵盤輸入乙個整數 1 20 則以該數字為矩陣的大小,把1,2,3 n n 的數字按照順時針螺旋的形式填入其中。例如 輸入數字2,則程式輸出 1 24 3輸入數字3,則程式輸出 1 2 3 8 9 4 7 6 5 輸入數字4,則程式輸出 1 2 3 4 12 13 14 5 11 16 15 6 1...