Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tree View question

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I have a tree view on a form and I'm trying to expand a certain node so that all its children are then visible.

I'm doing this from a different form:

frmMain.tvTreeView.Nodes.Item(i).Expanded = True

The node I'm trying to access does exist but nothing happens. Not even an error message. Is this because I'm trying it from another form?

Many Thanks

elziko

 
Try:

frmMain.tvTreeView.Nodes.Item(i).Child.EnsureVisible
frmMain.tvtreeView.refresh
 
I just seem to get an:

Object variable or With Block variable not set error. I see what your code is trying to do but it doesn't want to work. I also tried doing a refresh after my first attempt and that didn't help.

I've also tried it from the form that the tree view is on but that is also no help!

Mark, have you actually got this code working?

Many Thanks

elziko

 
I have, but I populate the child nodes on the Nodeclick event rather than fully populate the entire tree initially. I use a small routine to return a reference to the actual node and manipulate from there...

Code:
Public Function FindNode(strSrch As String) As Node
    Dim index As Integer
 
    Set FindNode = treTrans.Nodes(1) ' set default to root
    For index = 1 To treTrans.Nodes.Count
        If treTrans.Nodes(index).Text = strSrch Then
            treTrans.Nodes(index).EnsureVisible
            treTrans.Nodes(index).Selected = True
            Set FindNode = treTrans.Nodes(index)
            Exit For
        End If
    Next
  
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top