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
4

2 回答 2

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)

尝试暂停执行并在即时窗口中播放控件的不同属性。

于 2012-07-19T17:59:40.997 回答
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"
于 2012-07-20T03:15:12.830 回答