ListView具有如下的主要属性:ViewStyle为vsReport,RowSelect为Ture。
而且一个Item具有多个SubItem,这时,选择一个Item后当前行的颜色会发生改变,
其颜色为clActiveCaption。
我想让当前行的颜色改为其他的颜色,如何修改?

解决方案 »

  1.   

    呵呵,下午刚在另一个帖子里贴了,uses CommCtrl;procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    var
      r: TRect;
      i: Integer;
    begin
      with ListView1.Canvas do
      if cdsSelected in State then begin
        Brush.Color := clRed;
        r := Item.DisplayRect(drLabel);
        // Item
        FillRect(r);
        TextOut(r.Left+2, r.Top, Item.Caption);
        // SubItem
        for i := 0 to Item.SubItems.Count - 1 do begin
          ListView_GetSubItemRect(ListView1.Handle, Item.Index, i+1, LVIR_LABEL, @r);
          FillRect(r);
          TextOut(r.Left+5, r.Top, Item.SubItems[i]);
        end;
        DefaultDraw := False;
      end;
    end;
      

  2.   

    感谢sysu(死树) ,我随后就结贴。