Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CustomDrawItem in TTreeView

Posted on 1999-07-07
14
Medium Priority
?
1,704 Views
Last Modified: 2012-05-04
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!
0
Comment
Question by:bcrotaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1387112
try OnMeasureItem() (not sure for the name, if you need it I will take a look at it in the help file...)..... there you will get a pointer to a special structure, so you just change the height property, and that's all...

..-=ViKtOr=-..
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1387113
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
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1387114
see comment above!

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:bcrotaz
ID: 1387115
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
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1387116
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.).
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1387117
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.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1387118
I you call Node.DisplayRect(True) then you only get the text bounds.

Ciao, Mike
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1387119
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?
0
 
LVL 10

Accepted Solution

by:
Lischke earned 400 total points
ID: 1387120
Hi bcroatz,

long time no speak :-) Well, the integral node height implementation is buggy (often you can't simply scroll down when you have items which are expanded and some not while using different integral node heights. I your case, I assume, does only a full invalidate help. Can't give you any better advice, sorry.

Ciao, Mike
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1387121
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.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1387122
:-)

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
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1387123
Bugger.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1387124
Any known workarounds?
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1387125
Not that I know of :-/

Ciao, Mike
0

Featured Post

[Webinar] Protection from Cyberattacks

In this session, we’ll dive into the complexities of modern cyber threats and why only multi-vector protection can keep today’s businesses secure through the various stages of a cyberattack, across multiple vectors. Thursday September 14, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question