0

I am trying to color the rows of my ListView object. The colors are meant to alternate between white and grey and only differ from row to row when the captions of the rows do not match. For example, if 5 rows all have the same caption and are continuously next to each other then they should all be one color with the next row starting with the alternating color

procedure TMainForm.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin    
if Item.Index = 0 then begin
   sender.Canvas.Brush.Color := $f4f4f4;
   CurrentColor := $f4f4f4;
end
else if (Item.Caption = ListView1.Items[Item.Index + 1].Caption) then begin
  if CurrentColor = clWhite then begin
    sender.Canvas.Brush.Color := clWhite;
    CurrentColor := clWhite;
  end
  else begin//if CurrentColor = $f4f4f4 then begin
    sender.Canvas.Brush.Color := $f4f4f4;
    CurrentColor := $f4f4f4;
  end;
end
else begin
  if CurrentColor = clWhite then begin
    sender.Canvas.Brush.Color := $f4f4f4;
    CurrentColor := $f4f4f4;
  end;
  if CurrentColor = $f4f4f4 then begin
    sender.Canvas.Brush.Color := clWhite;
    CurrentColor := clWhite;
  end;
end
end;
Swell
  • 1
  • 2

0 Answers0