Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change TreeView node height, to draw 3 lines in a node

I use D7 with TreeView (not VirtualTreeView). How can I change node height to use OwnerDraw and draw 3 (or 5 or more) "lines" of text in node rectangle?

So tree should look like this (root node + 2 nodes are shown, aaa and bbb):

[+] Root node
 |
 |  [aaa1
 |--[aaa2222
 |  [aaa333
 |
 |  [bbb1
 |--[bbb2222
 |  [bbb333
 |
...

I know how to use owner-draw. But don't know how to make tall node rectangle.

like image 449
Prog1020 Avatar asked Jan 08 '14 16:01

Prog1020


1 Answers

The simplest way would be to set the node height when the node is already added in the tree view. This will save you from modifying the original VCL control code. What you need to do is set the iIntegral member of the TVITEMEX structure, which represents multiples of a default node height. If you'd need to set this height in pixels, you'd have to set the default node height by sending TVM_SETITEMHEIGHT message and setting the default node height to 1 pixel, but then the look of the tree view gets broken.

Here is a procedure which sets the node specified by the Node parameter to the height of Integral times of default node height:

procedure SetNodeHeight(Node: TTreeNode; Integral: Integer);
var
  ItemEx: TTVItemEx;
begin
  if not Node.Deleting then
  begin
    ItemEx.mask := TVIF_HANDLE or TVIF_INTEGRAL;
    ItemEx.hItem := Node.ItemId;
    ItemEx.iIntegral := Integral;
    TreeView_SetItem(Node.Handle, ItemEx);
  end;
end;

And the possible usage for setting a node to be 3 times higher than default node height:

procedure TForm1.Button1Click(Sender: TObject);
var
  Node: TTreeNode;
begin
  Node := TreeView1.Items.AddChild(nil, 'Node 3 times higher than default');
  SetNodeHeight(Node, 3);
end;

Surely you can extend the original VCL tree view class with a code like this, but I'll keep this upon you.

like image 147
TLama Avatar answered Nov 14 '22 23:11

TLama