Author: Lou Adler
The problem is that if the user clicks on a TListView outside the items the current
selected item is deselected. I want my TListView to always keep one item selected
so this never happens. What is the easiest way to accomplish this?
Answer:
1 { ... }2 Listview1.HideSelection := False;
3 { ... }4 5 { ... }6 var7 FPrevItem: TListItem;
8 { ... }9 10 procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
11 Shift: TShiftState; X, Y: Integer);
12 begin13 ifnot Assigned(Listview1.Selected) then14 Listview1.Selected := FPrevItem;
15 end;
16 17 procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem; Change:
18 TItemChange);
19 begin20 FPrevItem := Item;
21 end;