PDA

View Full Version : Treeview in VB



14-06-2002, 05:51 PM
Im wondering what is wrong with the following code.

Dim GoToNode As String
Options.Show
DoEvents: DoEvents
Set GoToNode = 'Registration'
Set Options.OptionsTree.SelectedItem = GoToNode

'Options is a form
'OptionsTree is a Treeview
'Registration is a node in the tree

And the error I get is 'Object Required' on the last GoToNode

17-06-2002, 01:39 PM
The reason why this doesn?t work is because the SelectedItem property of a TreeVew object expects a node object, not just a text string like ?Registration?. The reason for this is that there's more to a node than just some text (have a look at the Node object in the VB help). All you need to do is add a node object with your ?Registration? text to the TreeView and you should be away laughing e.g.:

Dim GoToNodeLabel As String

Options.Show

DoEvents: DoEvents

With Options.OptionsTree

.Nodes.Add , , 'Registration', 'Registration'

.Nodes.Add 'Registration', tvwChild, 'Child1', 'Child1'

.Nodes.Add 'Registration', tvwChild, 'Child2', 'Child2'

Set .SelectedItem = .Nodes('Registration')

End With

Double click the root ?Registration? node and you?ll see the child nodes.

17-06-2002, 01:40 PM
The reason why this doesn?t work is because the SelectedItem property of a TreeVew object expects a node object, not just a text string like ?Registration?. The reason for this is that there's more to a node than just some text (have a look at the Node object in the VB help). All you need to do is add a node object with your ?Registration? text to the TreeView and you should be away laughing e.g.:

Dim GoToNodeLabel As String

Options.Show

DoEvents: DoEvents

With Options.OptionsTree

.Nodes.Add , , 'Registration', 'Registration'

.Nodes.Add 'Registration', tvwChild, 'Child1', 'Child1'

.Nodes.Add 'Registration', tvwChild, 'Child2', 'Child2'

Set .SelectedItem = .Nodes('Registration')

End With

Double click the root ?Registration? node and you?ll see the child nodes.

17-06-2002, 01:44 PM
The reason why this doesn?t work is because the SelectedItem property of a TreeVew object expects a node object, not just a text string like ?Registration?. The reason for this is that there's more to a node than just some text (have a look at the Node object in the VB help). All you need to do is add a node object with your ?Registration? text to the TreeView and you should be away laughing e.g.:

Dim GoToNodeLabel As String

Options.Show

DoEvents: DoEvents

With Options.OptionsTree

.Nodes.Add , , 'Registration', 'Registration'

.Nodes.Add 'Registration', tvwChild, 'Child1', 'Child1'

.Nodes.Add 'Registration', tvwChild, 'Child2', 'Child2'

Set .SelectedItem = .Nodes('Registration')

End With

Double click the root ?Registration? node and you?ll see the child nodes.