TListView Caption-Cell of last row doesn't get colored

70 views Asked by At

I have been working with VCL for a couple months now, and could solve all my problems by googling, but this one got me stuck. I want to color a row in a TListView whenever the subItem at index 7 of that row does not contain a certain text (see code below). It all works well, except that the caption-cell (furthest to the left) of the last row does not get colored. I tried a couple hacks (e.g. enabling and then disbaling the ListView when drawing an item), but I didn't find one that doesn't break other stuff on the form (e.g. timers). Also, after I click on the cell, it does get colored... I'm using XE7 (C++Builder) on Windows 7. All suggestions are appreciated ;)

void __fastcall TBackupManagerForm::OverviewListViewCustomDrawItem(TCustomListView *Sender, TListItem *Item, TRect &Rect, TOwnerDrawState State)
{
    if ((*Item->SubItems)[7] != "someText") {
    Sender->Canvas->Brush->Color = clRed;
  }
  else {
    Sender->Canvas->Brush->Color = clWindow;
  }
  TRect r, rt;
  r = Item->DisplayRect(drBounds);
  Sender->Canvas->FillRect(Rect);
  r.Right = r.Left + (*OverviewListView->Columns)[0]->Width;
  rt = r;
  rt.Left += 5;
  rt.Top += 1;
  UnicodeString s = Item->Caption;
  Sender->Canvas->TextRect(rt, s, TTextFormat()<<tfSingleLine<<tfEndEllipsis);

  for (int i = 0; i < Item->SubItems->Count; i++) {
    ListView_GetSubItemRect(Sender->Handle, Item->Index, i+1, LVIR_BOUNDS,&rt);
    s = (*Item->SubItems)[i];
    Sender->Canvas->TextRect(rt, s, TTextFormat()<<tfSingleLine<<tfEndEllipsis);
  }
}

EDIT (Answering comments here because not enough rep :P)

@PaulMcCarthy Yeah, that seemed weird to me too...

@RemyLebeau Thanks for the suggestions, I implemented them.

Also, I managed to get it drawn properly by making an extra call to OverviewListView->Refresh() from outside CustomDrwaItem, but it still bugs me that it didn't work without it (pun somewhat intended).

0

There are 0 answers