Link to home
Start Free TrialLog in
Avatar of taposh_dr
taposh_dr

asked on

Treeview setfocus or setselected

Hello,
  I am using the treeview mousedown event to get another form. After the new form has been loaded, I would like the
  focus from the selected item to move down to the child node, I am unable to do it as setfocus is a read only function.
  I need to know how to solve it. Any Ideas???
T
ASKER CERTIFIED SOLUTION
Avatar of malharone
malharone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of patriziop
patriziop

Its right .selectednode is the answer, but a litle part of it.

You will need to code de beforeSelect event of the tree view using the FirstNode property.
Something like this:

Private Sub TreeView2_BeforeSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView2.BeforeSelect

        'First we verify the existence of a chilnode

        If Not e.Node.FirstNode Is Nothing Then

            'If it exists the we asign it to the selectednode property of the sender

            CType(sender, TreeView).SelectedNode = e.Node.FirstNode

            'and then we cancel the original operation, without this it will focus
            'the original node

            e.Cancel = True

        End If
End Sub

I forgot, before the if you can insert your form load code :-)