Serbin
Serbin

Reputation: 823

Scroll TreeView control to top

How can I scroll my Tree View control to the top?

For example we have some tree with a lot of elements:

Root element
|-- item 1
|-- item 2
|-- .....
|-- item 1567

Tree View control can display only 5 node at the same time. As result, when I press Expand button, it expand all items and shows me only the last 5 nodes.

I want so that after expanding it returns view to the first 5 nodes.

I tried to use this macros to return caret back to the root, but they take no effect:

TreeView_Select(hTreeView, hRoot, TVGN_CARET);
TreeView_SelectSetFirstVisible(hTreeView, hRoot);

Upvotes: 1

Views: 965

Answers (2)

cheny
cheny

Reputation: 2725

In C# winform, the following code makes it scroll back to top:

        ResultTree.ExpandAll();
        ResultTree.Nodes[0].EnsureVisible();

Using some Node instead of the whole tree, you scroll back to the node. Try if there is anything like this in C++.

Upvotes: 1

Adrian Roman
Adrian Roman

Reputation: 531

I assume you want to use Windows API (and the macros). You can ensure an item is visible with TreeView_EnsureVisible. If you do not have the root item you can get it with TreeView_GetRoot.

Upvotes: 1

Related Questions