Solved

TREEVIEW: set focus to 1st node after populating

Posted on 2001-06-28
11
797 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

10 Experts available now in Live!

Get 1:1 Help Now