![]() |
Selektion hervorheben in Listview ohne Fokus
sharky stellt
![]() Eine Einsatzmöglichkeit wäre beispielsweise die "Live-Suche" in einer Listview.
Delphi-Quellcode:
uses
..., CommCtrl;
Delphi-Quellcode:
const
LVHighliterColor: TColor = clAqua; LVHighliterColorOnFocused: TColor = clBlue;
Delphi-Quellcode:
Ein Aufruf könnte z.B. im OnChange eines Edits so aussehen:
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;
Delphi-Quellcode:
procedure TForm1.Edit1Change(Sender: TObject);
var i: Integer; begin for i := 0 to ListView1.Items.Count - 1 do begin if Pos(Edit1.Text, ListView1.Items[i].SubItems[0]) = 1 then begin ListView1.ItemIndex := i; break; end; end; end; Anmerkungen:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz