Solved

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

Posted on 2004-10-14
3
959 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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