TVirtualStringTree and vertical scroll are not working properly

I learned how to use TVirtualStringTree and I found it to be excellent. I have one custom PackedList non-visual list that is populated by another thread. And I want to show the entire list of content in TVirtualStringTree in real time. So I put one timer on mainform to update HexLog (which is TVirtualStringTree) RootNodeCount every 500 ms.

All my data appears on VirtualStringTree, and I have no speed problem, very nice. But there is one problem with the vertical scrollbar. When I press Ctrl + End on a control to go to the end of the list, it goes somewhere in the middle. Similarly, when I drag the scroll bar to the end, it does not end. But HexLog knows the DataCount. Why is it not coming to an end? If I press a couple of times to Ctrl + END, it will go to the end.

In internal timer mode, I want to say HexLog to go to the end of the list by code. How to do this and how to handle the vertical scrollbar correctly?

procedure TMainForm.StatusUpdateTimerTimer(Sender: TObject); begin if (FirpList.ComOperationCount > 0) and (PacketList.Items.Count <> FirpList.ComOperationCount) then begin HexLog.RootNodeCount := PacketList.Items.Count; end; end; procedure TMainForm.HexLogMeasureItem(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer); begin if Sender.MultiLine[Node] then begin TargetCanvas.Font := Sender.Font; NodeHeight := HexLog.ComputeNodeHeight(TargetCanvas, Node, 1, FirpList.ComOperations[Node^.Parent^.Index].DataAsHexString(FAppSettings.HexLogColumnCharWidth) + #13#10); end; end; 

Appearance of hexlog

The recommended answer from TLama is not working properly, see image for explanation: TLama solution is not working

See this link for a detailed explanation of the image: http://i43.tinypic.com/1445thi.png

+6
source share
1 answer

To jump to the end of the tree, call ScrollIntoView(GetLast) .

To go to a specific node, the control needs to add the heights of all previous nodes so that it can determine the correct offset.

Your nodes have different heights. If you do not initialize the actual heights of the nodes somewhere, then the control uses the DefaultNodeHeight property for any uninitialized nodes. It seems like the height is less than any actual node height in your tree, so the control finishes calculating the offset, which is less than expected, and scrolls there instead of where you intended.

Make sure you are handling the OnMeasureItem event and you have the toVariableNodeHeight option set in Options.MiscOptions . If you do not, the control will only use the assigned height for each node and use the default height for any uninitialized node.

You can get the behavior described here by manually assigning NodeHeight instead of setting toVariableNodeHeight and processing OnMeasureItem .

+6
source

Source: https://habr.com/ru/post/912602/


All Articles