Solved

moving a treeview's scrollbars to the top of the treeview

Posted on 2004-10-14
3
957 Views
Last Modified: 2006-11-17
I am trying to move the scrollbars of a treeview control to the top of the control.  When I add a large number of nodes and expand all the nodes via code, the treeview control moves to the bottom of the treeview.  I want the scrollbars to be at the top of the treeview.  I am pretty sure you can do this using the windows API SendMessage() function, but I dont know what values to give to the function to get it to work.  If there is a way to do it using c# code instead of the API call I would prefer to do that.

Thank You
0
Comment
Question by:clintonm9
3 Comments
 
LVL 1

Expert Comment

by:Kahhoe
ID: 12315870
Add the code below:

directoryTreeView.AfterExpand += new TreeViewEventHandler(directoryTreeView_AfterExpand);

private void directoryTreeView_AfterExpand(object sender, TreeViewEventArgs e)
{
     while(directoryTreeView.SelectedNode.Parent!=null)
     {
          directoryTreeView.SelectedNode = directoryTreeView.SelectedNode.Parent;
     }

     directoryTreeView.SelectedNode.EnsureVisible();
}

hope this is what you want..
0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 12316007
Hi

just check this link. It's working for scrolling panel programatically.
But from the available source code u will get all the information about API's
to play with ScrollBars

http://www.codeproject.com/cs/miscctrl/CustomAutoScrollPanel.asp

Hope it will help
Cheers
Jatinder
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 125 total points
ID: 12318802
Why not just:

if (myTreeView.Nodes.Count > 0)
  myTreeView.Nodes[0].EnsureVisible();
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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