Einzelnen Beitrag anzeigen

Benutzerbild von Sharky
Sharky

Registriert seit: 29. Mai 2002
Ort: Frankfurt
8.252 Beiträge
 
Delphi 2006 Professional
 
#6

Re: ListView-Eintrag selektieren ohne ListView-Fokus

  Alt 20. Aug 2006, 08:21
Hai Matze,

ich hatte eben etwas Zeit

Knalle doch mal aus Spass diesen Code in das OnOwnerDrawItem deines ListViews:
Delphi-Quellcode:
uses
  CommCtrl;

const
  LVHighliterColor: TColor = clAqua;
  LVHighliterColorOnFocused: TColor = clBlue;

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  ColumnRect: TRect;
  TextRect: TRect;
  Drawstate: Cardinal;
  SubitemIndex: Integer;
begin
  Drawstate := 0;
  DefaultDraw := False;
  if TListView(Sender).ViewStyle = vsReport then
  begin
    with (sender as TListView) do
    begin
      if (Item.Selected) then
      begin
        if (Sender.Focused) then
        begin
          Canvas.Pen.Color := LVHighliterColorOnFocused;
          Canvas.Brush.Color := LVHighliterColorOnFocused;
        end
        else
        begin
          Canvas.Pen.Color := LVHighliterColor;
          Canvas.Brush.Color := LVHighliterColor;
        end;
      end
      else
      begin
        Canvas.Pen.Color := clWhite;
        Canvas.Brush.Color := clWhite;
      end;
      ListView_GetItemRect(Handle, Item.Index, ColumnRect, LVIR_BOUNDS);
      Canvas.Rectangle(ColumnRect);
      ListView_GetItemRect(Handle, Item.Index, TextRect, LVIR_LABEL);
      DrawText(Canvas.Handle, Pchar(Item.Caption), Length(Item.Caption),
        TextRect, Drawstate);
      for SubitemIndex := 1 to Columns.Count - 1 do
      begin
        ListView_GetSubItemRect(Handle, Item.Index, SubitemIndex, LVir_Label, @textrect);
        DrawText(Canvas.Handle, Pchar(Item.SubItems[SubitemIndex - 1]),
          Length(Item.SubItems[SubitemIndex - 1]),
          TextRect, Drawstate);
      end;
    end;
  end;
end;
Stephan B.
  Mit Zitat antworten Zitat