Recent

Author Topic: VirtualTreeView MultiLine Cpomponents  (Read 3004 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
VirtualTreeView MultiLine Cpomponents
« on: April 02, 2021, 09:59:22 am »
Hello

Can Some1 please Explain ho i get Multi line text on a VirtualStringTree

See attached Picture

Thanks :)

balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #1 on: April 02, 2021, 11:29:49 am »
Quote
Can Some1 please Explain ho i get Multi line text on a VirtualStringTree
Like this:
Code: Pascal  [Select][+][-]
  1. type
  2.   PData = ^TData;
  3.   TData = record
  4.     FName: String;
  5.     //...
  6.   end;
  7.  
  8. procedure TForm1.Button1Click(Sender: TObject);
  9. var
  10.   Node: PVirtualNode;
  11.   Data: PData;
  12. begin
  13.   VST.TreeOptions.MiscOptions := VST.TreeOptions.MiscOptions + [toVariableNodeHeight];
  14.  
  15.   Node := VST.AddChild(nil);
  16.   Data := VST.GetNodeData(Node);
  17.   Data^.FName := 'this is the first line' + sLineBreak + 'this is the second line';
  18.   VST.MultiLine[Node] := True;
  19.  
  20.   Node := VST.AddChild(nil);
  21.   Data := VST.GetNodeData(Node);
  22.   Data^.FName := 'aaaa' + sLineBreak + 'bbbb' + sLineBreak + 'cccc';
  23.   VST.MultiLine[Node] := True;
  24. end;
  25.  
  26. procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  27.   Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
  28. var
  29.   Data: PData;
  30. begin
  31.   Data := VST.GetNodeData(Node);
  32.   CellText := Data^.FName;
  33. end;
  34.  
  35. procedure TForm1.VSTMeasureItem(Sender: TBaseVirtualTree;
  36.   TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer);
  37. begin
  38.   if Sender.MultiLine[Node] then
  39.   begin
  40.     TargetCanvas.Font := Sender.Font;
  41.     NodeHeight := VST.ComputeNodeHeight(TargetCanvas, Node, -1);
  42.   end;
  43. end;

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #2 on: April 06, 2021, 09:04:13 am »
Did not work for me..

MeasureItem did never get Executed because multiline was not True (Because it was set after creating node)
When i used a Button to set Node height, then it worked .. so what am i mising ?

balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #3 on: April 06, 2021, 09:19:53 am »
Did you create the OnGetText and OnMeasure events for the virtual tree as in the attached image?

Quote
MeasureItem did never get Executed because multiline was not True (Because it was set after creating node)
You can only set the multiline property after the node is created, but this shouldn't be a problem.

Can you please attach your project source? Also what is your Lazarus/FPC version? What VST do you use?


Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #4 on: April 06, 2021, 09:35:26 am »
Yes ... attached Example of mine

Code: Pascal  [Select][+][-]
  1.    //Created on ONCreate Event
  2.     //Root
  3.     XNode := VSTBasis.AddChild(Nil);
  4.     if VSTBasis.AbsoluteIndex(XNode) > -1 then begin
  5.        Data := VSTBasis.GetNodeData(Xnode);
  6.        Data^.Text := dbSprachen.FieldByName(FeldD).AsString;
  7.        Data^.Tag:= dbRegelung.FieldByName('ID').AsString;
  8.        VSTBasis.MultiLine[XNode] := True;
  9.     end;
  10.  
  11.  
  12. procedure TfrmRegelung.VSTBasisGetText(Sender: TBaseVirtualTree;
  13.   Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  14.   var CellText: String);
  15. var
  16.   Data: PTreeData;
  17. begin
  18.   Data := VSTBasis.GetNodeData(Node);
  19.   case Column of
  20.     0: CellText := Data^.Text;
  21.   end;
  22. end;
  23.  
  24. procedure TfrmRegelung.VSTBasisMeasureItem(Sender: TBaseVirtualTree;
  25.   TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer);
  26. begin
  27.   if Sender.MultiLine[Node] = True then
  28.   begin
  29.     TargetCanvas.Font := Sender.Font;
  30.     NodeHeight := VSTBasis.ComputeNodeHeight(TargetCanvas, Node, -1);
  31.   end;
  32. end;
  33.  
  34.  

 Did this Line --> VST.TreeOptions.MiscOptions := VST.TreeOptions.MiscOptions + [toVariableNodeHeight];
 In Object inspector... shouldn't make any difference ?



balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #5 on: April 06, 2021, 09:54:44 am »
Quote
Did this Line --> VST.TreeOptions.MiscOptions := VST.TreeOptions.MiscOptions + [toVariableNodeHeight];
 In Object inspector... shouldn't make any difference ?
No.

I attach my project zipped(Lazarus 2.0.12/FPC 3.2.0).

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #6 on: April 06, 2021, 10:31:50 am »
Ur Example Did work .. had it same way in my appication but somehow didn't work

Found out that Checkbox does not work either with TriStateCheckboxes

wich worked in my prev application well .. is there some option wich blocks those events ?

balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #7 on: April 06, 2021, 10:45:38 am »
Quote
Ur Example Did work .. had it same way in my appication but somehow didn't work
I cannot help without seeing the project.

Quote
Found out that Checkbox does not work either with TriStateCheckboxes
In order for the checks to work, you have to:
1. Set toCheckSupport to true(TreeOptions->Misc Options)
2. After the node is created, add the following line:
Code: Pascal  [Select][+][-]
  1.   Node := VST.AddChild(nil);
  2.   Data := VST.GetNodeData(Node);
  3.   Data^.FName := 'aaaa' + sLineBreak + 'bbbb' + sLineBreak + 'cccc';
  4.   VST.MultiLine[Node] := True;
  5.   Node^.CheckType := ctTriStateCheckBox;  //<-- this one

Quote
is there some option wich blocks those events ?
No. Those events works fine for me.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #8 on: April 06, 2021, 10:58:50 am »
Have all Settings the Same, Except that my TreeView is in a PageControl.

Edit: Attached Project
« Last Edit: April 06, 2021, 11:14:17 am by Weitentaaal »

balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #9 on: April 06, 2021, 04:09:04 pm »
@Weitentaaal
I modified unit1(pas/dfm), now both multiline and check support works.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #10 on: April 07, 2021, 10:59:40 am »
Thanks  :)

What did u change ?

balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #11 on: April 07, 2021, 11:40:56 am »
Quote
Thanks  :)
You're welcome!

Quote
What did u change ?
Not much. For multiline see procedure AddFeuchteRegelung, for checkbox I changed VTV->CheckImageKind from ckDarkCheck to ckSystemDefault.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #12 on: April 07, 2021, 12:43:52 pm »
IS there any way it Resizes the line itself ? So i dont have to put LineBreak ... for example when i use a String out of Database ?

balazsszekely

  • Guest
Re: VirtualTreeView MultiLine Cpomponents
« Reply #13 on: April 07, 2021, 01:47:08 pm »
IS there any way it Resizes the line itself ? So i dont have to put LineBreak ... for example when i use a String out of Database ?
If you don't put a LineBreak, then you have a single long line not multi line. I guess it's possible to calculate the width of the cell text, compare width the column width and break the text manually, but you have to do the calculation yourself.   
 

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: VirtualTreeView MultiLine Cpomponents
« Reply #14 on: April 07, 2021, 03:36:22 pm »
was already about to do it

Got this far but there si in additional the left space where the dotted lines are ... so it would be different for any level of the tree.
any way to find out how much space there is from Left Border of VST to beginn of String ?

Code: Pascal  [Select][+][-]
  1. //vars
  2.   Data: PTreeData;
  3.   width : Integer;
  4.   //temp, temp2 : String;
  5.   howOften, i : Integer;
  6.   s : Array of String;
  7.   temp : String;
  8.  
  9. //Code
  10. width := VST.Canvas.GetTextWidth(text);
  11. IF width + (Here Should be the difference between String begin and left border of VST (0)) > VST.Header.Columns.Items[0].Width then begin
  12.      howOftenToSplit:= round((VST.Header.Columns.Items[0].Width / width) + 0.5);
  13.  
  14.      {for i := 1 to howOften do begin
  15.         s[i] := (LeftStr(text, i * round(Length(text) / howOften)));   //Here will be a better calculation ut just for the testing it will be fine (Does not work  :-X)
  16.      end;}
  17.      s := text.Split(LeftStr(text, round(Length(text) / howOften)));
  18.  
  19.      temp:= '';
  20.      for i := 1 to howOften - 1 do begin;
  21.         temp := temp + s[i] + sLineBreak;
  22.      end;
  23.      temp := temp + s[i] ;
  24.   end;
  25.  

Please don't judge the String rebuild .. wrote this out of my head --> so does not work  :-[

 

TinyPortal © 2005-2018