Board index » delphi » Help: TListView SubItems Don't Show on OwnerDraw

Help: TListView SubItems Don't Show on OwnerDraw

Hi All
I have a ListView(vsReport,Grid), with 6 Columns. i Add the Items and
SubItems from a File Loaded, within another handler. EveryThing works
fine if OwnerDraw is False. now, i want Subitems 2..4 to be checked for
none '0', and show them in Red. i add the following:
------
procedure TForm1.ListViewCustomDrawSubItem(Sender: TCustomListView;  Item:
TListItem; SubItem: Integer; State: TCustomDrawState;  var DefaultDraw:
Boolean);
var
  R :TRect;
  I: Integer;
  S: String;
begin
  ListView.Canvas.Font := ListView.Font;
  ListView.Canvas.Brush.Color := ListView.Color;
  R := Item.DisplayRect(drBounds);
  for i := 0 to SubItem do
    R.Left := R.Left + ListView.Columns[i].Width;
  S := Item.SubItems[SubItem];
  if (SubItem > 1 ) and (S <> '0') then
    ListView.Canvas.Font.Color := clRed  Else
      ListView.Canvas.Font.Color := clBlack;
  ListView.Canvas.FillRect(R);
  ListView.Canvas.TextOut(R.Left,R.Top,S);
  DefaultDraw := False;
end;

procedure TForm1.ListViewCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  DefaultDraw := True;
end;
-----------
Only Items Show in the ListView,  No SubItems?! what's wrong?
.....
TIA
jacob

 

Re:Help: TListView SubItems Don't Show on OwnerDraw


Quote
jacob muntner wrote:
> procedure TForm1.ListViewCustomDrawSubItem(Sender: TCustomListView;  Item:
> TListItem; SubItem: Integer; State: TCustomDrawState;  var DefaultDraw:
> Boolean);
> begin

      ...
      for i := 0 to SubItem do
        R.Left := R.Left + ListView.Columns[i].Width;

Quote
> end;

Jacob,

IMO you count 1 too much in the for clause. Try

for i := 0 to SubItem - 1 do
   R.Left := R.Left + ListView.Columns[i].Width;

Besides it would have been much simpler if Delphi had made use of the
rectangle that windows actually sends in the underlying windows message. Then
you wouldn't have to calculate this position.

Regards,
Helge S?gaard

Re:Help: TListView SubItems Don't Show on OwnerDraw


Well, i think the count is right, but i tried, still no good!?
SubItem "n" matches column "n+1", so if i want to find Rect.left
of Subitem "2", i have to sum widths of columns 0..2(excluding
column "3"). i added an extra line to calculate Rect.right,by using
column "n+1", but still no go.
anyway, i added a ShowMessage at the end of the procedure, to see
if it's called, and it's  NOT?!
i'm really confused now, what is wrong?
----
Thanks
jacob

Quote
Helge S?gaard <h...@2ndc.dk> wrote in message

news:3B83661E.69D5A3CC@2ndc.dk...
Quote

> jacob muntner wrote:

> > procedure TForm1.ListViewCustomDrawSubItem(Sender: TCustomListView;
Item:
> > TListItem; SubItem: Integer; State: TCustomDrawState;  var DefaultDraw:
> > Boolean);

> > begin

>       ...
>       for i := 0 to SubItem do
>         R.Left := R.Left + ListView.Columns[i].Width;

> > end;

> Jacob,

> IMO you count 1 too much in the for clause. Try

> for i := 0 to SubItem - 1 do
>    R.Left := R.Left + ListView.Columns[i].Width;

> Besides it would have been much simpler if Delphi had made use of the
> rectangle that windows actually sends in the underlying windows message.
Then
> you wouldn't have to calculate this position.

> Regards,
> Helge S?gaard

Re:Help: TListView SubItems Don't Show on OwnerDraw


Jacob,

Sorry that I've mislead you. :-)

Helge

Other Threads