I was seeing this code and, with the logical adaptations, it suits me perfectly for my application in BCB 6 but I would like to know how I could do to change the background color of the cells. When I do it with a TListView I use the Brush property of the Canvas:
void __fastcall TForm1 :: ListView1CustomDrawItem (TCustomListView * Sender, TListItem * Item, TCustomDrawState State, bool & DefaultDraw)
{
Sender-> Canvas-> Brush-> Color = clWhite;
Sender-> Canvas-> Font-> Color = clBlack;
Sender-> Canvas-> Font-> Style = TFontStyles () >> fsBold;
}
But I have verified that Sender-> Canvas-> Brush-> Color generates a compilation error ('TCustomControl: Canvas' is not accessible) and using TargetCanvas-> Brush-> Color does not produce any results.
The TVirtualStringTree uses a rather different set of procedures for painting the cells of the tree. If you look in the help you will find that there are several events occuring for each cell. The ones you probably are interested in are:
OnBeforeCellPaint()provides theCellRectparameter, which you can use to fill the whole background, including tree expand symbol and eventual node image, or, usingContentRect, excluding tree expand symbol space,and then use
OnPaintText()to draw the textAlternatively, maybe easier to use only
OnDrawText()in which you can both fill the text background (but, excluding tree expand symbol and image) and draw the textBtw, I recommend looking at the help file in the dl package, for further details regarding painting the tree. The chapter Paint Cycles and Stages starts with this: The most complex process in Virtual Treeview is without doubts its painting. Read here what stages Virtual Treeview enters during paint and how you can customize this process.