[Lazarus] TListView - how to make selected line stay selected?

Bo Berglund bo.berglund at gmail.com
Mon Aug 19 18:21:06 CEST 2019


I have a dialog which is used to enable changing the order of certain
items. The items are displayed in a TListView component in report
mode, each item occupies one line and shows several properties in the
columns.
Now I want to be able to select the row (list.Rowselect = true) when
clicking on it. This works OK.
Then I have a button which moves the item up and another button to
move it down the list.
In my code I do the following for moving up (lvCutList is the listview
showing the data, FVideoCuts ia a dynamic array of TVideoCut records):

procedure TfrmEditCuts.btnUpClick(Sender: TObject);
var
  i, l: integer;
  V1: TVideoCut;
begin
  i := lvCutList.ItemIndex;
  if i < 1 then exit;  //Not selected or already at top
  V1 := FVideoCuts[i-1];
  FVideoCuts[i-1] := FVideoCuts[i];
  FVideoCuts[i] := V1;
  ShowCuts(FVideoCuts); // <= Repopulate the listview from data
  lvCutList.ItemIndex := i-1; //<= This is no longer visible
end;

So the end result is that the line is moved up one position in the
list and I set the itemindex property such that the moved line is
still selected.
But it does not show on screen...

The selection of the line disappeares immediately when the button is
clicked and only returns if I forcibly click in the listview in some
place that will not move the selection, for example in the unpopulated
area at the bottom.

What I would like to see is that the selection color *stays visible*
even if focus is moved away from the listview component.

How can this be accomplished?

I am pretty sure I could do this when I used Delphi a few years back
at work (now retired)...


-- 
Bo Berglund
Developer in Sweden



More information about the lazarus mailing list