Solved

TREEVIEW: set focus to 1st node after populating

Posted on 2001-06-28
11
801 Views
Last Modified: 2006-11-17
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
Comment
Question by:jas777
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 2

Expert Comment

by:agriggs
ID: 6234802
Try: Treeview.Nodes(1).EnsureVisible after you have loaded the treeview.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6234804
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
 

Expert Comment

by:jsopher
ID: 6234836
dave-

   can you give me the syntax
0
 

Expert Comment

by:jsopher
ID: 6234841
jas777

i think you should try and extend the length of the treeview
0
 

Author Comment

by:jas777
ID: 6234855
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

Accepted Solution

by:
bhess1 earned 100 total points
ID: 6234928
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
 
LVL 32

Expert Comment

by:bhess1
ID: 6234934
Note - you also use EnsureVisible only after the Treeview is fully populated.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6234950
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
 

Author Comment

by:jas777
ID: 6235019
thanks dude, you rule
0
 
LVL 2

Expert Comment

by:agriggs
ID: 6236087
I am just curious why

tvwMine.Nodes("Root").EnsureVisible

works and

Treeview.Nodes(1).EnsureVisible

doesn't?  Ok, I give.
0
 

Author Comment

by:jas777
ID: 6236357
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now