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 に答える