Hi...
When I refere to selected Node in TreeView control, when no selected nodes are, error occurs.. How can I check, is there any selected Node in my TreeView control?
Thank you very much.
Printable View
Hi...
When I refere to selected Node in TreeView control, when no selected nodes are, error occurs.. How can I check, is there any selected Node in my TreeView control?
Thank you very much.
Hello there...
Well, here is a way to find out if you have any selected nodes in your tree.
For i = 1 To TreeView1.Nodes.Count
If TreeView1.Nodes.Item(i).Selected = True Then
...hold the i somewhere and you have the selected node...
End If
Next
Hope it helped
vvang10
Ok, thanks a lot...
But probably there must be an easiest way? Probably using some standart method, or comparing like
if TreeControl.Nodes.SelectedItem = Nothing ..... ?????
I think that was the easiest way to find out if you have selected nodes in Treeview.
There is an easier way, browsing for each nodes in a treeview can be a pain if you have a lot of nodes (like it is often the case with treeview), try that code:
Remove that line afterward :)Code:Private Sub Command1_Click()
Dim objNode As Node
'Get the selected node
Set objNode = Me.TreeView1.SelectedItem
'Remove the selection to test
Set objNode = Nothing
'Test if selection
If objNode Is Nothing Then
MsgBox "No selection"
Else
MsgBox "Selection: " & objNode.Text
End If
End Sub
Set objNode = Nothing
JeffB - hope it helps
Ok! thanks a lot!:)
This is the VB6 forum, and VS2010 is supported in the .Net forum...