ListView自绘时子项内容不显示
是不是要在别的事件中增加什么处理?
void __fastcall TForm14::lv1DrawItem(TCustomListView *Sender, TListItem *Item, TRect &Rect,
TOwnerDrawState State)
{
if( Item->Index == Sender->ItemIndex )
{
Sender->Canvas->Brush->Color = clMedGray ;
}
else
{
if(Item->Index %2 == 0 )
Sender->Canvas->Brush->Color = clSkyBlue ;
else
Sender->Canvas->Brush->Color = clMoneyGreen ;
}
Sender->Canvas->FillRect(Rect);
Sender->Canvas->TextOutW(Rect.Left+2,
(Rect.Height() - Sender->Canvas->TextHeight(Item->Caption))/2 + Rect.Top ,
Item->Caption);
}
void __fastcall TfrmTest::ListView1DrawItem(TCustomListView *Sender,
TListItem *Item, TRect &Rect, TOwnerDrawState State)
{
TListView *lv = (TListView *)Sender;
lv->Canvas->Brush->Color = Item->Index % 2? clYellow: clGreen;
if(State.Contains(odSelected))
lv->Canvas->Brush->Color = clRed;
lv->Canvas->FillRect(Rect);
//
int nOffsetLeft(2);
if(lv->SmallImages)
{
lv->SmallImages->Draw(lv->Canvas, Rect.Left + 1, Rect.Top, Item->ImageIndex);
nOffsetLeft += lv->SmallImages->Width;
}
lv->Canvas->Brush->Style = bsClear;
lv->Canvas->TextRect(Rect, Rect.Left + nOffsetLeft, Rect.Top + 2, Item->Caption); // 显示文字
int nItemWidth = 0;
for(int i=0; i<Item->SubItems->Count; i++)
{
nItemWidth = nItemWidth + lv->Columns->Items[i]->Width;
lv->Canvas->TextOut(Rect.Left + nItemWidth,
Rect.Top + 2, Item->SubItems->Strings[i]); // 显示文字
}
}