Recent

Author Topic: [SOLVED] TreeView onAdvancedCustomDrawItem issue with scrolling  (Read 2719 times)

DmytroLev

  • New Member
  • *
  • Posts: 10
[SOLVED] TreeView onAdvancedCustomDrawItem issue with scrolling
« on: October 29, 2018, 12:33:58 pm »
Hello!
I'm trying to put additional information to TreeView in a "column-like" style: (see picture 1 https://drive.google.com/open?id=1AvTcCykHJC13id5jwn06eFziXD1z3p8U).
I do it with onAdvancedCustomDrawItem, drawing necessary info to Canvas.
Everything is ok. But when I scroll the TreeView down, the items that were outside visible part of the window are shown without that additionally drawn info (see picture 2 https://drive.google.com/open?id=149ks0-1WHnCMvXsIZfwoV1P8C3o7pdRV).
It's the same on Lazarus 1.8.2 and 1.8.4, both Linux and Windows.
Any ideas how to deal with it?
P.S. As a temporary workaround I use "force" redraw by timer, but this has its own issues.
« Last Edit: October 30, 2018, 06:35:52 am by DmytroLev »

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TreeView onAdvancedCustomDrawItem issue with scrolling
« Reply #1 on: October 29, 2018, 05:29:52 pm »
You need to show us the code section in the Custom Draw event. Something tells me you maybe using the wrong canvas or rectangle etc..
The only true wisdom is knowing you know nothing

DmytroLev

  • New Member
  • *
  • Posts: 10
Re: TreeView onAdvancedCustomDrawItem issue with scrolling
« Reply #2 on: October 29, 2018, 06:15:20 pm »
Here is the code:
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.TreeViewRahunkyAdvancedCustomDrawItem(
  2.   Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState;
  3.   Stage: TCustomDrawStage; var PaintImages, DefaultDraw: Boolean);
  4. var
  5.     dlRightBorder:integer;
  6.     dlLeftBorder:integer;
  7.     dlTextOfNode,dlNomerRahunku:string;
  8.     dlCreateDate:TDateTime;
  9.     dlRect: TRect;
  10. begin
  11.    dlLeftBorder:=TreeViewRahunky.Left;
  12.    dlRightBorder:=TreeViewRahunky.Width;
  13.    dlTextOfNode:=Node.Text;
  14.    dlNomerRahunku:=dl_GetTextBeginning(dlTextOfNode,#9);//here I extract an ID to get additional data from DB
  15.    dlCreateDate:=SQLQueryRahTab.Lookup('SRT_NOMER_SUBRAH',dlNomerRahunku,'SRT_DENPOYAVY');//Getting additional data (planned to add more in future, and show in several drawn "columns")
  16.    with TreeViewRahunky.Canvas do
  17.      begin
  18.       if node.Selected then begin
  19.        Brush.Style := bsSolid;
  20.        Brush.Color := clHighLight;
  21.        FillRect(rect(Node.DisplayTextLeft,Node.Top,dlRightBorder,Node.Bottom));
  22.        Brush.Style := bsClear;
  23.        TextOut(Node.DisplayTextLeft,Node.Top,Node.Text);
  24.       end
  25.       else begin
  26.        Brush.Style := bsSolid;
  27.        Brush.Color := clCream;
  28.        FillRect(rect(dlRightBorder-210,Node.Top,dlRightBorder-90,Node.Bottom));
  29.        Brush.Style := bsClear;
  30.       end;
  31.       TextOut(dlRightBorder-200,Node.Top+1,FormatDateTime('dd.mm.yyyy',dlCreateDate));
  32.     end;
  33. end;
  34.  

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TreeView onAdvancedCustomDrawItem issue with scrolling
« Reply #3 on: October 30, 2018, 12:30:24 am »
Try using  Node.DisplayRect(True/False ?) for the actual Canvas rectangle area.

This reports the actual location you need to be, from there you can calculate, It think the parameters you are using are based
from a non scrolled windows, because you can also query the ScrolledLeft and ScrollTop information..

The Display rectangle should return a TRECT with all the info in it.


The only true wisdom is knowing you know nothing

DmytroLev

  • New Member
  • *
  • Posts: 10
Re: TreeView onAdvancedCustomDrawItem issue with scrolling
« Reply #4 on: October 30, 2018, 06:33:21 am »
Thanks a lot, jamie!

Your advice helped, now I set the coordinates based on DisplayRect, and the additionally drawn info now doesn't disappear.
Left and right coordinates where ok, I only had to get Top and Bottom from DisplayRect instead of Node.Top and Node.Bottom:
Code: Pascal  [Select][+][-]
  1. dlRect:=Node.DisplayRect(true);
  2. {...}
  3. FillRect(rect(dlRightBorder-210,dlRect.Top,dlRightBorder-90,dlRect.Bottom));
« Last Edit: October 30, 2018, 07:04:16 am by DmytroLev »

 

TinyPortal © 2005-2018