|
Question : tvwChild not declared error when using treeview in vb.net
|
|
Hi, I am trying to convert vb 6.0 to vb.net code where i am using treeview . i get error .tvwChild not declared how can i correct it
Regards
|
|
Answer : tvwChild not declared error when using treeview in vb.net
|
|
Although the names, and much about their appearance, are the same the TreeView controls pre-NET and post-NET are completely different animals.
Specifically, for present purposes, the pre-NET TreeView has a single Nodes collection which itself contains all the levels of nodes. That is why the .Add method takes arguments to specify the relative and relationship - so that it can be indicated which existing node it "belongs" to and what is the nature of that "belonging" - first in the level occupied by the existing node, last in that level, immediately before the existing node, immediately after it, or as a child of it.
Post-NET the TreeView's own Nodes collection only contains the top-level Nodes. Then each Node in that collection has its own Nodes collection. So, in the post-NET TreeView, to add a top-level node, we use
Dim myNewNode As New TreeNode MyTreeView.Nodes.Add(myNewNode)
And then to add a child to that, we use
Dim myNewChildNode As New TreeNode myNewNode.Nodes.Add(myNewChildNode)
And to add a child to that, we use
Dim myNewGrandChildNode As New TreeNode myNewChildNode.Nodes.Add(myNewGrandChildNode)
And so on. To put nodes in specific positions - first, last, previous, next - we use .Nodes.Insert.
What this means is that you cannot simply "adapt" code for pre-NET TreeViews to post-NET TreeViews. If you want to continue to use the pre-NET code then you should add a reference to the Common Controls Library to your project and use the old-style TreeView. If you want to use the native, post-NET TreeVew, you will need to recast your code on the lines above.
Roger
|
|
|
|