Recent

Author Topic: Virtual Tree View selections. How to?  (Read 1807 times)

slivitin

  • New member
  • *
  • Posts: 7
Virtual Tree View selections. How to?
« on: January 26, 2023, 02:27:16 pm »
Hi.
I want to show two Virtual Tree Views - one for "models", and one for "locations". I want to show highlited selection without any user actions. My program does find location and model in these trees and I want to highlitу founded strings.
But founded string in the trees hasn't any selections...
How to change such behaviour?
I want to automatically highlite founded as olive (for example)...
First picture - default behaviour of the tree.
Second picture - after my selection (first location, then model, then select another some component of the form), so trees not in the focus.

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Virtual Tree View selections. How to?
« Reply #1 on: January 26, 2023, 03:12:28 pm »
Selected[Node] := True/False ?

balazsszekely

  • Guest
Re: Virtual Tree View selections. How to?
« Reply #2 on: January 26, 2023, 03:18:42 pm »
@slivitin

A small demo application would be nice, it's much easier to modify that. Anyways let's say you have the following data structure:
Code: Pascal  [Select][+][-]
  1. type
  2.   PData = ^TData;
  3.   TData = record
  4.     FID: Integer;
  5.     FName: String;
  6.     //...
  7.     FHighlight: Boolean; //add this one
  8.   end;

After you find the node:
Code: Pascal  [Select][+][-]
  1. var
  2.   Node: PVirtualNode;
  3.   Data: PData;
  4. begin
  5.   //find the node here
  6.   Data := VST.GetNodeData(Node);
  7.   Data^.FHighlight := True;
  8.   VST.RepaintNode(Node);
  9.   VST.InvalidateNode(Node)
  10. end;

Finally add OnBeforeCellPaint event to the tree:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.VSTBeforeCellPaint(
  2.   Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
  3.   Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
  4.   var ContentRect: TRect);
  5. var  
  6.   Data: PData;
  7. begin
  8.   Data := VST.GetNodeData(Node);
  9.   if Data^.FHighlight then
  10.   begin
  11.     TargetCanvas.Brush.Color := clOlive;
  12.     TargetCanvas.FillRect(ContentRect);
  13.   end;
  14. end;
« Last Edit: January 26, 2023, 03:20:43 pm by GetMem »

slivitin

  • New member
  • *
  • Posts: 7
Re: Virtual Tree View selections. How to?
« Reply #3 on: January 28, 2023, 11:04:06 am »
Selected[Node] := True/False ?

Thank's! I forgot := True   :-[

GetMem, thank you too!
« Last Edit: January 28, 2023, 11:06:34 am by slivitin »

 

TinyPortal © 2005-2018