• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 933
  • Last Modified:

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.
0
jas777
Asked:
jas777
  • 3
  • 2
  • 2
  • +2
1 Solution
 
agriggsCommented:
Try: Treeview.Nodes(1).EnsureVisible after you have loaded the treeview.
0
 
Dave_GreeneCommented:
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
0
 
jsopherCommented:
dave-

   can you give me the syntax
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jsopherCommented:
jas777

i think you should try and extend the length of the treeview
0
 
jas777Author Commented:
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.
0
 
Brendt HessSenior DBACommented:
Do you have a root item in your Treeview that all other items depend on?  Then you should be able to specify that node using the EnsureVisible property:

tvwMine.Nodes("Root").EnsureVisible

Do this after sorting the Treeview (if you sort it)

You could also insert the data into the Treeview in Reverse order (bottom to top).  Thus, the last entered item would be the one on top.
0
 
Brendt HessSenior DBACommented:
Note - you also use EnsureVisible only after the Treeview is fully populated.
0
 
Dave_GreeneCommented:
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.
0
 
jas777Author Commented:
thanks dude, you rule
0
 
agriggsCommented:
I am just curious why

tvwMine.Nodes("Root").EnsureVisible

works and

Treeview.Nodes(1).EnsureVisible

doesn't?  Ok, I give.
0
 
jas777Author Commented:
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
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now