views:

323

answers:

3

Hi,

A TVirtualStringTree object with custom node height, How to reliably scroll Virtual TreeView to the bottom (i.e. the scrollbar gets to the bottom)?

I tried calling tree1.FullExpand then tree1.ScrollIntoView.(tree1.GetLast), but it does not work.

Thank you in advance.

+2  A: 

ScrollIntoView works well for me. You can also try tree1.FocusedNode := tree1.GetLast;

Are you setting custom node height in OnMeasureItem event? If it doesn't work, try to set tree's DefaultNodeHeight to the bigger value and in OnMeasureItem event change it to lower. I noticed that tree recalculates scrollbar's length better that way.

Linas
Thanks Linas. Yes, I'm setting custom height for each node in OnMeasureItem event base on the node contents. setting 'tree1.FocusedNode' does not work. I'll try what you said about setting the larges height for all nodes then adjust the values.
Edwin
Hi Linas,The second approach you suggested works! It seems that Virtual Treeview uses DefaultNodeHeight when doing calculation during a scroll operation.
Edwin
That's correct, Edwin. The alternative would be for the control to initialize every node in the tree, even the ones that haven't had to be visible yet. That can be time-consuming.
Rob Kennedy
A: 

This also should work:

tree1.TopNode := tree1.GetLast
Thanks Straveu. it does not work also...PS. I can get the treeview completed printed if I manually (not programmatically) scroll down to the last node.
Edwin
A: 

I've had the same problem working with TVirtualDrawTree's. You have to make sure that node heights are computed before the tree actually scrolls.

This is what I do:

1.- Add this code to the OnInitNode event so that the tree knows that the height of the new node must be computed:

Node.States := node.States + [vsMultiline] - [vsHeightMeasured];

2.- In the OnMeasureItem, if you can't compute the height (e.g. node not initialized yet), make sure you tell the tree to repeat the call when needed: In the OnMeasureItem event handler:

If (Node = Nil) Or (Node = tree.RootNode) Then Begin Exclude(Node.States, vsHeightMeasured); Exit; End;

NodeData := tree.GetNodeData(Node); If (NodeData = Nil) Or (NodeData^.XMLNode = Nil) Then Begin Exclude(Node.States, vsHeightMeasured); Exit; End; Try // Code to measure node height here.

Except Exclude(Node.States, vsHeightMeasured); End;

I hope it helps you.

Juan Antonio Jiménez Palmero