TTreeView, OnCustomDrawItem how to proceed....
Posted on 2006-05-16
I'm trying to develop an application that handles diffrent records in a database(n-tire). The database have a field named "folder" which indicates the named place for the record. The application have a TreeView placed on the left side of the form, and the nodes are named after the "folders" in the database. (like March 2006, April 2006). All records can have different "status" (like open/closed) and I would like to display the count of records having the status "open" for each folder in the treview, with bolded text and the count of open records in blue. (jus like MS Outlook). I have a timer on the application checking against the server for new records continously, so this feature can not be a part of the actual treeviews events (like OnCustomDrawItem, I've tried that one but couldn't manage to forece the repainting of each node without messing with the treeview). Below You can find the code that I've tried so far, but as I mentioned before, it works as long as You play with the TreeView not the background functionality Im looking for.
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
if Node.Text = 'Inbox' then
s := '('+IntToStr(CDS.RecordCount)+')';
Sender.Canvas.Font.Style := [fsBold];
r := Node.DisplayRect(true);
bmp := TBitmap.Create;
bmp.Width := Canvas.TextWidth(s);
bmp.Height := Canvas.TextHeight(S);
bmp.Canvas.Font.Color := clBlue;
bmp.Canvas.Brush.Style := bsClear;
bmp.Canvas.TextOut(0, 0, s);
Pt.x := r.Left + sender.Canvas.TextWidth(Node.Text)+8;
Pt.y := r.Top + 2;
DC := GetDC(sender.Handle);
BitBlt(DC, pt.x, pt.y, BMP.Width, BMP.Height, BMP.Canvas.Handle, 0, 0, SRCCOPY);
DefaultDraw := True;
The solution would be to manage the forced repainting and/or develop a totally new feature I think. Any suggestions?