bcrotaz
asked on
CustomDrawItem in TTreeView
Is it possible to change the height of individual items when overriding CustomDrawItem in a TCustomTreeView descendant?
The only way I have found so far is to globally change the height by changing the font size. But this changes the indent as well, which I don't want to do.
Ideas please!
The only way I have found so far is to globally change the height by changing the font size. But this changes the indent as well, which I don't want to do.
Ideas please!
Viktor, your answer is not true. There is no such event like OnMeasureItem in TTreeView.
bcrotaz,
you can't use individually sized items in TTreeView, even with custom draw. The reason is that M$ has only included the global item height (for all nodes) property and the socalled integral height (separate for each node) which is actually a multiplication factor of the global item height. Unfortunately, also in D4, the intergral height hasn't been implemented by Borland. I suggest usin gmy freeware treeview called TreeNT (www.delphipages.com, tree/list section), which supports the integral node height.
By using a little trick you should be able then to assign each node its own height. Set ItemHeight to a small value (a few pixel) and assign each node an integral height. I haven't tried this, but you could use an item height of one pixel and then the integral height is actually the pixel height. You might need to adjust the indentation too, but that's also very easy.
Ciao, Mike
bcrotaz,
you can't use individually sized items in TTreeView, even with custom draw. The reason is that M$ has only included the global item height (for all nodes) property and the socalled integral height (separate for each node) which is actually a multiplication factor of the global item height. Unfortunately, also in D4, the intergral height hasn't been implemented by Borland. I suggest usin gmy freeware treeview called TreeNT (www.delphipages.com, tree/list section), which supports the integral node height.
By using a little trick you should be able then to assign each node its own height. Set ItemHeight to a small value (a few pixel) and assign each node an integral height. I haven't tried this, but you could use an item height of one pixel and then the integral height is actually the pixel height. You might need to adjust the indentation too, but that's also very easy.
Ciao, Mike
ASKER
see comment above!
ASKER
Mike -
In TreeNT, how do you get the DisplayRect for a node?
For the future, when you fire an event, if you do it via a protected virtual method, it makes the descendant author's job much easier!
eg
OnBeforePaint
Bryan
In TreeNT, how do you get the DisplayRect for a node?
For the future, when you fire an event, if you do it via a protected virtual method, it makes the descendant author's job much easier!
eg
OnBeforePaint
Bryan
Getting the display rect is easy. Just query Node.DisplayRect (the node must have been shown at least once for this to work, though). This method exists also in TTreeView.
While doing custom draw use either OnBeforeItemPaint or OnAfterItemPaint. There's a paramter ItemRect which describes the entire line of the item to be drawn. Unfortunately, you won't get the text rectangle only. This is Microsoft's fault not TreeNT's!
Regarding virtual event wrappers: I agree with you in principle, but TreeNT has grown already so large (it's almost 7000 code lines, just for one control and the memory requirement is also much too high), I have decided to leave such changes up to the user of TreeNT, if (s)he needs it, sorry.
Ciao, Mike
PS: I recommend looking at the demo program source which came with TreeNT, as you need to consider other things when doing owner draw (scrolling etc.).
While doing custom draw use either OnBeforeItemPaint or OnAfterItemPaint. There's a paramter ItemRect which describes the entire line of the item to be drawn. Unfortunately, you won't get the text rectangle only. This is Microsoft's fault not TreeNT's!
Regarding virtual event wrappers: I agree with you in principle, but TreeNT has grown already so large (it's almost 7000 code lines, just for one control and the memory requirement is also much too high), I have decided to leave such changes up to the user of TreeNT, if (s)he needs it, sorry.
Ciao, Mike
PS: I recommend looking at the demo program source which came with TreeNT, as you need to consider other things when doing owner draw (scrolling etc.).
ASKER
Is the display rect equivalent to the text rect?
I need to get the rect from the left side of the text (the accumulated indents) to the right side of the control.
I need to get the rect from the left side of the text (the accumulated indents) to the right side of the control.
I you call Node.DisplayRect(True) then you only get the text bounds.
Ciao, Mike
Ciao, Mike
ASKER
Lischke - it worked! Thanks.
Problems with repainting if you change the height of a node. That node repaints, and the tree structure repaints (the +, - and node lines), but the other nodes don't.
Try just drawing an outline rect in the owner draw for a node, then changing the IntegralHeight of one node.
Apart from that it's OK - any hints?
Problems with repainting if you change the height of a node. That node repaints, and the tree structure repaints (the +, - and node lines), but the other nodes don't.
Try just drawing an outline rect in the owner draw for a node, then changing the IntegralHeight of one node.
Apart from that it's OK - any hints?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is it your implementation or MS's?
If yours, can you point me at the buggy method, and I'll have a go at fixing it.
If yours, can you point me at the buggy method, and I'll have a go at fixing it.
:-)
It's MS'. TreeNT as well as TreeView are just wrappers for the system treeview provided by MS. I spent over a year on writing TreeNT. Believe me, if the error were in my implementation I would have fixed it (in particular when I know it...).
Ciao, Mike
It's MS'. TreeNT as well as TreeView are just wrappers for the system treeview provided by MS. I spent over a year on writing TreeNT. Believe me, if the error were in my implementation I would have fixed it (in particular when I know it...).
Ciao, Mike
ASKER
Bugger.
ASKER
Any known workarounds?
Not that I know of :-/
Ciao, Mike
Ciao, Mike
..-=ViKtOr=-..