2012-07-19 93 views
0

即時通訊新手到vb6,我不知道如何更改變量「childCount」變化時的根/父節點?如何更新根/父節點文本

感謝

例如:

Dim nodx As Node 
dim childCount as integer 

childCount = 0 

Set TreeView1.ImageList = ImageList1 

'Add root Node 
Set nodx = TreeView1.Nodes.Add(, , "Root", "Root Node have " & childCount & " child" ,"Closed") 

'Expand root node so we can see what's under it 
nodx.ExpandedImage = "Open" 
nodx.Expanded = True 

'Create a child node under the root node 
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child1", "Child node 1", "Closed") 

childCount =childCount + 1 
'Expand this node so we can see what's under it 
nodx.ExpandedImage = "Open" 
nodx.Expanded = True 

'Create several more children 
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child2", "Child node 2", "Leaf") 

childCount =childCount + 1 

Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child3", "Child node 3", "Leaf") 

childCount =childCount + 1 

Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child4", "Child node 4", "Leaf") 

childCount =childCount + 1 

Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child5", "Child node 5", "Leaf") 

childCount =childCount + 1 

回答

1

因爲要更新的根節點(第一節點),你已經知道了索引號爲1,那麼你的任務是特別容易。

TreeView1.Nodes.Item(1).Text = "Root Node have " & CStr(childCount) 

您還可以更新新節點的根目錄。在你的樣品是一樣的指數1

TreeView1.Nodes.Item(TreeView1.Nodes.Count).Root.Text = "Root Node have " & CStr(childCount) 

嘗試暫停執行,並與控制的不同性質的立即窗口發揮。

+0

我找到了解決辦法感謝@Beaner對他的想法,我做的是:昏暗的非石油出口作爲節點 – user1537510 2012-07-20 03:04:13

0

我找到了解決辦法感謝@Beaner對他的想法,我做的是:

Dim nodx As Node 
Dim nodChild As Node 
dim childCount as integer 

Set nodx = TreeView1.Nodes.Add(, , "Root", "Root Node have " & childCount & " child" ,"Closed") 

'Expand root node so we can see what's under it 
nodx.ExpandedImage = "Open" 
nodx.Expanded = True 

'Create a child node under the root node 
Set nodChild = TreeView1.Nodes.Add("Root", tvwChild, "Child1", "Child node 1", "Closed") childCount =childCount + 1 

'Expand this node so we can see what's under it nodx.ExpandedImage = "Open" nodx.Expanded = True 
'Create several more children 
Set nodChild = TreeView1.Nodes.Add("Root", tvwChild, "Child2", "Child node 2", "Leaf") childCount =childCount + 1 

Set nodChild = TreeView1.Nodes.Add("Root", tvwChild, "Child3", "Child node 3", "Leaf") childCount =childCount + 1 

Set nodChild = TreeView1.Nodes.Add("Root", tvwChild, "Child4", "Child node 4", "Leaf") childCount =childCount + 1 

Set nodChild = TreeView1.Nodes.Add("Root", tvwChild, "Child5", "Child node 5", "Leaf") childCount =childCount + 1 

nodx.Text = "Root Node have " & childCount & " child" 
+1

你不需要'nodx'變量,因爲'TreeView1.Nodes(1)'是根。 – wqw 2012-07-20 11:47:08

相關問題