Link to home
Start Free TrialLog in
Avatar of jas777
jas777

asked on

TREEVIEW: set focus to 1st node after populating

hello-

this is a stupid question, but for some reason, when i populate my treeview from database entries, the treeview scrolls to the bottom.

basically, the top item(1st node) is not visible, unless you manually scroll back up.

Q: how do keep the focus on the first node, so it is visible after populating the treeview.
Avatar of agriggs
agriggs

Try: Treeview.Nodes(1).EnsureVisible after you have loaded the treeview.
The treeview will scroll as it is loaded, nothing you can do about that, but you can set the first item as the selected item after the load completes, to resync the view
dave-

   can you give me the syntax
jas777

i think you should try and extend the length of the treeview
Avatar of jas777

ASKER

i tried agriggs comment, and was unnsuccessful.

basically, my treeview is a certain size, and because after populating, the items in the treeview, require a longer treeview, the scrolling automatically occurs.

if you guys have an EXAMPLE of setting the selected item as the first node, i would really appreciate it.
ASKER CERTIFIED SOLUTION
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

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
Note - you also use EnsureVisible only after the Treeview is fully populated.
For i = 0 To 100
    Set nodX = TreeView1.Nodes.Add(1, tvwChild)
    nodX.Text = List1.List(i)
Next i

Treeview1.Nodes(1).Selected = True
nodX.EnsureVisible     ' Make sure the node is visible.
Avatar of jas777

ASKER

thanks dude, you rule
I am just curious why

tvwMine.Nodes("Root").EnsureVisible

works and

Treeview.Nodes(1).EnsureVisible

doesn't?  Ok, I give.
Avatar of jas777

ASKER

agriggs, i apologize, but i didn't implement yours correctly.  i used the index as 0, not 1 - as you reccommeded.

let me know how i can award you some points at least, and i will.

if you want me to post a "dummy" question just for you, let me know.

sorry man, my brain is on cloud 9