2008. március 11., kedd

Use the OnDraw methods of a TListView in vsReport view style


Problem/Question/Abstract:

Does anyone know how to use the OnDraw methods in the TListView - vsReport? I want to draw both the list item and the list item's sub-items, but it seems to me that the OnDraw only gets called on the item. I have tried all the draw methods but cannot realy figure out how to draw in the subitems rect.

Answer:

You are right, it gets called by the TListItem but since you have the TListItem, you can draw the subitems as well. Example DrawItem:

{ ... }
if Item.Index = 0 then
  Sender.Canvas.Brush.Color := clRed
else
  Sender.Canvas.Brush.Color := clYellow;
Sender.Canvas.FillRect(Rect);
for x := 0 to TListView(Sender).Columns.Count - 1 do
  if x = 0 then
    Sender.Canvas.TextOut(Rect.Left + 2, Rect.Top, Item.Caption)
  else
    Sender.Canvas.TextOut((Rect.Left + 2) + Sender.Column[x].Width,
      Rect.Top, Item.SubItems.Strings[x - 1]);
{ ... }

Nincsenek megjegyzések:

Megjegyzés küldése