Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TVirtualStringTree and vertical Scroll is not working properly

I have learned how to use TVirtualStringTree, and I've found it excellent. I have one custom non-visual list called PackedList which is filled by another thread. And I want to show all list content in TVirtualStringTree at realtime. So I put one timer on the mainform to update HexLog's (which is TVirtualStringTree) RootNodeCount every 500ms.

All my data appears on the VirtualStringTree, and I don't have any speed problem, very nice. But there is one problem with Vertical Scroll bar. When I press Ctrl+End on the control in order to jump to the end of the list, it goes somewhere on the middle. Similarly when I drag scroll bar to the end, it doesn't go to the end. But HexLog knows the DataCount. Why doesn't it jump to the end? If I press couple of times to Ctrl+END then it reaches to the end.

Inside timer routine, I want to say HexLog to jump to the end of the list by code. How can I do this and How to handle vertical scroll bar properly?

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

Suggested reply by TLama is not working properly, see the image for explanation: TLama solution is not working

See that link for detailed image explanation: http://i43.tinypic.com/1445thi.png

like image 671
Mehmet Fide Avatar asked Apr 06 '12 13:04

Mehmet Fide


1 Answers

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

To scroll to a particular node, the control needs to add up the heights of all the prior nodes so it can determine the proper offset.

Your nodes have varying heights. If you're not initializing the actual heights of the nodes somewhere, then the control uses the DefaultNodeHeight property for any uninitialized nodes. It looks like that height is shorter than any actual node height in your tree, so the control ends up calculating an offset that is smaller than expected, and scrolls there instead of where you intended.

Make sure you're handling the OnMeasureItem event, and that you have the toVariableNodeHeight option set in Options.MiscOptions. If you don't, then the control will just use the currently assigned height for each node, and use the default height for any uninitialized node.

You could get the behavior you report here if you manually assign NodeHeight instead of setting toVariableNodeHeight and handling OnMeasureItem.

like image 132
Rob Kennedy Avatar answered Sep 28 '22 05:09

Rob Kennedy