Hello everyone,
I am writing a piece of software in C++ RAD studio 2010 and got a question about TreeView.
Is it possible to use multicolor text in a TTreeView component? I could not find a easy way but to implement custom drawing which seems to be weird nowadays. Are there any straight-forward ways or maybe additional components that can do it for me?
UPDATE
Ended up doing it with custom drawing.
void __fastcall TForm1::TreeView1AdvancedCustomDrawItem(TCustomTreeView *Sender, TTreeNode *Node,
TCustomDrawState State, TCustomDrawStage Stage, bool &PaintImages,
bool &DefaultDraw)
if (Stage == cdPostPaint)
{
TRect rect(Node->DisplayRect(true));
String redText = "redtext";
String greenText = " greentext";
Sender->Canvas->Font->Color = clRed;
Sender->Canvas->Refresh();
Sender->Canvas->TextOut(rect.Left, rect.Top, redText);
rect.Left += Sender->Canvas->TextWidth(redText);
Sender->Canvas->Font->Color = clGreen;
Sender->Canvas->Refresh();
Sender->Canvas->TextOut(rect.Left, rect.Top, greenText);
rect.Left += Sender->Canvas->TextWidth(greenText);
}
It was important to use Refresh so that the method works.
Also, after having realized that I needed multiline text to output I switched to VirtualTreeView component from soft-gems