StrataFrame Forum

TreeNode question - EnsureVisible

http://forum.strataframe.net/Topic4261.aspx

By Greg McGuffey - 11/8/2006

For some reason I cannot get a TreeNode to become visible. The code looks like this:



' Find a node based on key

dim aNode as TreeNode = me.tvwAny.Find(key,false)(0)



' Make the node visible, but it doesn't when I do it

aNode.EnsureVisible()



' This theortically will also make it visible

me.tvwAny.SelectedNode = aNode



So, is there some property on the treeview that I must set for this to work? Am I doing something wrong?



I appreciate any help offered!

Greg
By Trent L. Taylor - 11/8/2006

I think that your problem is that the parent node is not expanded.  I wrote this little test to create 100 items, each with a child node, and then select the child node inside of the last parent node and make sure it is selected and visible.  This code is dirty, but it should give you a general idea:

''' <summary>
''' Populates the tree view with the slides
''' </summary>
''' <remarks></remarks>
Private Sub LoadSlidesInTree()
'-- Establish Locals
Dim loNode As TreeNode
Dim lnCnt As Integer

For lnCnt = 0 To 100
    loNode =
New TreeNode("Item " & lnCnt.ToString())
    loNode.Nodes.Add(
"Child Node")

    Me.MyTreeView.Nodes.Add(loNode)
Next

'-- Expand and show the last node
loNode.ExpandAll()
Me.MyTreeView.SelectedNode = loNode.Nodes(0)
loNode.Nodes(0).EnsureVisible()

End Sub

You should see some results like this:

By Greg McGuffey - 11/8/2006

I figured out my problem.



Both of these do work:



myTree.SelectedNode=someNode

someNode.Ensurevisible()



They both expand the tree and scroll tree so the node is visible.



My problem was that the node I was working with wasn't valid...long story Crazy



Thanks for you help in any case!