2004. február 21., szombat

Ensure that at least one item in a TListView is always selected


Problem/Question/Abstract:

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:

{ ... }
Listview1.HideSelection := False;
{ ... }

{ ... }
var
  FPrevItem: TListItem;
  { ... }

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if not Assigned(Listview1.Selected) then
    Listview1.Selected := FPrevItem;
end;

procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem; Change:
  TItemChange);
begin
  FPrevItem := Item;
end;

Nincsenek megjegyzések:

Megjegyzés küldése