Forum > General

[Solved] VirtualDrawTree question-Child displayed in wrong location

(1/1)

bobonwhidbey:
I haven't been able to find a good example using the TVirtualDrawTree so I'm stumbling in the dark. This simple example I've put together has a record with only the one Caption:string. Here's how I'm adding root and child records...seems to be working:

--- 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 TForm.VDTaddClick(Sender: TObject);var  Data: PMyRec;  Node: PVirtualNode;begin  with VDT do    case (Sender as TButton).Tag of      0:      begin // add to root        Node := VDT.AddChild(nil);        Data := VDT.GetNodeData(Node);        Data^.Caption := 'Root ' + IntToStr(RootNodeCount);      end;      1: if Assigned(FocusedNode) then  // add as child        begin          ChildCount[FocusedNode] := ChildCount[FocusedNode] + 1;          Expanded[FocusedNode] := True;          InvalidateToBottom(FocusedNode);          Node := VDT.AddChild(nil);          Data := VDT.GetNodeData(Node);          Data^.Caption := 'Child ' + IntToStr(RootNodeCount);//          Data^.Caption := 'Child ' + IntToStr(Node.Index);        end;    end;end; 
When I display the tree with this, you can see, in the attachment, that the tree indentions seem to be correct but the text is showing up at the bottom, like a main root record rather than a child record.


--- 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 TForm.VDTDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);var  Data: PMyRec;  R: TRect;  I, w: integer;  s, s1: string;begin  with Sender as TVirtualDrawTree, PaintInfo do  begin    Data := VDT.GetNodeData(Node);    SetBKMode(Canvas.Handle, TRANSPARENT);    R := ContentRect;    if vsSelected in Node^.States then      Canvas.Font.Color := clWhite    else      Canvas.Font.Color := clBlack;    s := Data^.Caption;    DrawText(Canvas.Handle, PChar(s), Length(s), R, DT_LEFT or      DT_BOTTOM or DT_SINGLELINE);  end;end; 
Can someone provide help or a good VDT example?

jamie:
Try the CELLRECT instead for the text out...

bobonwhidbey:
Same problem :(  Attached shows the results after adding 3 at the root, then selecting the middle line and adding a child.

--- 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";}};} ---  with Sender as TVirtualDrawTree, PaintInfo do  begin    Data := VDT.GetNodeData(Node);    s := Data^.Caption;    SetBKMode(Canvas.Handle, TRANSPARENT);    if vsSelected in Node^.States then      Canvas.Font.Color := clWhite    else      Canvas.Font.Color := clBlack;    R := CellRect;    DrawText(Canvas.Handle, PChar(s), Length(s), R, DT_LEFT or      DT_BOTTOM or DT_SINGLELINE);  end; 

jamie:
you add a child node but you don't give it a parent node so its just going to keep showing in the root path..

on the second case step, use the focused node for example as the parent node instead of nil

Navigation

[0] Message Index

Go to full version