Hi Rob,
Quote
> There's no problem changing colors of items that are not selected,
> but it seems selected items always get overwritten.
This is an unfortunate property of the list view common control.
Namely, the selected items are not affected by the changes made in
response to the Custom Draw messages when the CDRF_DODEFAULT flag is
returned (DoDefault set to true). What you can do, however, is set the
DoDefault parameter to false, then render the items manually in the
color of choice. Here's an example for vsIcon ViewStyle...
void __fastcall TForm1::ListView1CustomDrawItem(
TCustomListView *Sender,
TListItem *Item, TCustomDrawState State, bool &DefaultDraw)
{
if (State.Contains(cdsSelected))
{
ListView1->Canvas->Brush->Color = clRed; // for example
ListView1->Canvas->Font->Color = clGreen; // for example
RECT IconRect = Item->DisplayRect(drIcon);
RECT CaptionRect = Item->DisplayRect(drLabel);
// calculate the icon's horizontal position
int IconLeft = IconRect.left + 0.5 *
(IconRect.right - IconRect.left -
ListView1->LargeImages->Width);
// draw the icon
HIMAGELIST HIml =
reinterpret_cast<HIMAGELIST>
(ListView1->LargeImages->Handle);
ImageList_Draw(HIml, Item->ImageIndex,
ListView1->Canvas->Handle,
IconLeft, IconRect.top + 2,
ILD_TRANSPARENT);
// draw the caption
ListView1->Canvas->FillRect(CaptionRect);
DrawText(ListView1->Canvas->Handle, Item->Caption.c_str(),
Item->Caption.Length(), &CaptionRect,
DT_CENTER | DT_WORDBREAK);
DefaultDraw = false;
return;
}
DefaultDraw = true;
Other styles can be rendered using a similar technique.
Good luck!
--
Damon Chandler (TeamB)
http://bcbcaq.freeservers.com