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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With