Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

Try this:

SendMessage(VST.Handle, WM_VSCROLL, SB_BOTTOM, 0);
PostMessage(VST.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This also should work:

tree1.TopNode := tree1.GetLast

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top