Link to home
Start Free TrialLog in
Avatar of A1ternity
A1ternity

asked on

Multiple colors in a treeview node's Text

Hi everyone.

I'm using a TTreeView to display a list of item which have subitems... so far so good. Problem is that for each parent item I have more information that I'd like to display Next to the item between parenthesis, the problem I have is that I'd like the text between parenthesis to be of another color. I wrote a nice little procedure in the AdvancedCustomDraw of my treeview (see below) but for some reasons I can't get the 2 colors... Anybody has an idea?

//////////////////// BeginCode

      if cdsSelected in state then
        Font.Color := clHighlightText
      else
        Font.Color := clWindowText;

      TextOut(NodeRect.Left, NodeRect.Top, 'blah');
      li_TextWidth := TextWidth('blah');

      if cdsSelected in state then
        Font.Color := clInactiveCaptionText
      else
        Font.Color := clGray;

      TextOut(NodeRect.Left + 1 + li_TextWidth, NodeRect.Top, '(ExtraText)');
   
//////////////////// EndCode

The whole text for the Node ends up begin of clInactiveCaptionText color... Anybody has an idea?
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of A1ternity
A1ternity

ASKER

Well... this method works as long as you don't have to put more than 1 color on the text of a single particular node.

Thanks for the help but sadly it didn't work for what I'm trying to do...
Wanna bet??
I do not have time to follow up on this bet but maybe you should look into
the HTMLTreeview from TMS. It allows you to format your node text with
a limited set of HTML tags, including font tags and can have multiple colors
on one line.

http://www.tmssoftware.com/htmltv.htm
In HTMLTreeview, this sets the text Blah to Blue and the Text (Extra Text) to red with two space between:
(Set the Node's text property when you edit them)
<font face="MS Sans Serif" size="8" color="clblue">Blah</font>&nbsp; &nbsp;<font face="MS Sans Serif" size="8" color="clred">(Extra Text)</font>
I will take a deeper look at the code sample you provided... I only had time to try it quickly this morning and can't return to it right now. As for using the HTML Treeview I'd rather avoid using another component...

I'll keep you informed...
Still havn't had the time to try the solution and that part of the project is put aside for now...

Still here are your points! (won't say I'm not a good sports! Didn't even try your solution and I still pay! ;)