How to reliably scroll Virtual TreeView to the bottom?

假装没事ソ 提交于 2019-11-30 20:33:16

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.

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
Juan Antonio Jiménez Palmero

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!