How to reliably scroll Virtual TreeView to the bottom?

左心房为你撑大大i 提交于 2019-12-19 02:51:45

问题


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.


回答1:


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.




回答2:


Try this:

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



回答3:


This also should work:

tree1.TopNode := tree1.GetLast



回答4:


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.



来源:https://stackoverflow.com/questions/2839397/how-to-reliably-scroll-virtual-treeview-to-the-bottom

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