Forum > Lazarus Extra Components

Virtual Tree View selections. How to?

(1/1)

slivitin:
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:
Selected[Node] := True/False ?

GetMem:
@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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  PData = ^TData;  TData = record    FID: Integer;    FName: String;    //...    FHighlight: Boolean; //add this one  end;
After you find the node:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  Node: PVirtualNode;  Data: PData;begin  //find the node here  Data := VST.GetNodeData(Node);  Data^.FHighlight := True;  VST.RepaintNode(Node);  VST.InvalidateNode(Node)end;
Finally add OnBeforeCellPaint event to the tree:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.VSTBeforeCellPaint(  Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;  Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;  var ContentRect: TRect);var    Data: PData;begin   Data := VST.GetNodeData(Node);  if Data^.FHighlight then  begin    TargetCanvas.Brush.Color := clOlive;    TargetCanvas.FillRect(ContentRect);  end;end;

slivitin:

--- Quote from: zeljko on January 26, 2023, 03:12:28 pm ---Selected[Node] := True/False ?

--- End quote ---

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

GetMem, thank you too!

Navigation

[0] Message Index

Go to full version