Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Treeview scroll options

Posted on 2002-05-20
7
Medium Priority
?
384 Views
Last Modified: 2006-11-17
I would like to create two command buttons: one that scrolls a treeview to the top for viewing and the other that scrolls the treeview to the bottom.  How do I do this?  Please provide me with the code.

Thanks
0
Comment
Question by:perkster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7022185
Here is a very simple way to do this.  I have only tested it with 50 nodes so I don't know how fast it will be if there are many nodes.  There may also be a better way to do this.  I will keep checking.

Private Sub Command1_Click()
   
    'Scroll bottom
    TreeView1.Nodes(1).Selected = True
    TreeView1.Nodes(TreeView1.Nodes.Count).Selected = True
   
End Sub

Private Sub Command2_Click()
   
    'Scroll top
    TreeView1.Nodes(TreeView1.Nodes.Count).Selected = True
    TreeView1.Nodes(1).Selected = True
   
End Sub
0
 
LVL 4

Accepted Solution

by:
gencross earned 200 total points
ID: 7022195
Here is a better way to do this.  Hope this helps.

Private Sub Command1_Click()
   
   'Scroll bottom
   TreeView1.Nodes(TreeView1.Nodes.Count).EnsureVisible  
 
End Sub

Private Sub Command2_Click()
   
   'Scroll top
   TreeView1.Nodes(1).EnsureVisible      

End Sub
0
 
LVL 2

Expert Comment

by:Crin
ID: 7022335
Hi,

Yes, you surely will use Select or EnsureVisible methods, but the algo gencross supposed is not good, since nodes indices are not guaranteed to be from top to bottom, but in order of their load.

So, you should use FirstSibling, LastSibling, Expanded and some other properties of the treeview control.

Also, it is quite difficult to scroll line by line from CURRENT position, since there is no "IsVisible" property for the node object.

By the way, why not to use standard treeview scrollbars?

Sincerely,
Crin
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:gencross
ID: 7022480
I'm not sure, but I believe the highest index of a control (treeview, combobox, listbox, collection, etc...) is going to be assigned to the last item (node).  You cannot, for example, assign index 10 to the first item in the treeview.  You can assign a key of "10" to the item, but the index should always start at 0 or 1 (1 in the case of the treeview) and the last item should have the highest index.  Not necessary the highest key, but that doesn't matter because key and index are two different things.  Please let me know if I am wrong.
0
 
LVL 2

Expert Comment

by:Crin
ID: 7022494
Hi,

Simple test will show indices applying.
Open new project, add MS Windows Common Controls, place treeview on the form, paste the code and run the form.

The code is obvious, so you will simple see what is node  index for particular node.

Private Sub Form_Load()

Dim nd As Node


Me.TreeView1.Nodes.Add , , "a", "a"
Me.TreeView1.Nodes.Add , , "b", "b"

Me.TreeView1.Nodes.Add "a", tvwChild, "a1", "a1"
Me.TreeView1.Nodes.Add "a", tvwChild, "a2", "a2"
Me.TreeView1.Nodes.Add "b", tvwChild, "b1", "b1"
Me.TreeView1.Nodes.Add "a", tvwChild, "a3", "a3"

For Each nd In Me.TreeView1.Nodes
  nd.Text = nd.Index
Next

End Sub


Sincerely,
Crin

0
 
LVL 2

Expert Comment

by:Crin
ID: 7022516
By the way - numeric key values are prohibited for the Node object as well as for ListItem object, so you can not assign "10" value to particular node key value, in spite of the fact key property is string.

Also, Index property is read-only for Node (and ListItem) and it achieve value while Add method execution for Nodes collection. So, you also cannot operate with it after node is loaded except to *get* its value.

Sincerely,
Crin
0
 

Author Comment

by:perkster
ID: 7023111
Perfect.  Thanks all.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

596 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