diff --git a/lcl/include/customlistview.inc b/lcl/include/customlistview.inc index 0232e26a3f..ea8f3d7e10 100644 --- a/lcl/include/customlistview.inc +++ b/lcl/include/customlistview.inc @@ -1429,11 +1429,17 @@ function TCustomListView.GetSelection: TListItem; var i: Integer; begin - if not OwnerData then + if OwnerData and not MultiSelect then begin - {according to Delphi docs - we always must return first selected item, not the last selected one - see issue #16773} + if FSelectedIdx>=0 then begin + FOwnerDataItem.SetDataIndex(FSelectedIdx); + Result:=FOwnerDataItem; + end else + Result:=nil; + end + else begin + { according to Delphi docs we always must return first selected item, + not the last selected one see issue #16773 } if not (lffSelectedValid in FFlags) or MultiSelect then begin FSelected := nil; @@ -1448,12 +1454,6 @@ begin Include(FFlags, lffSelectedValid); end; Result := FSelected; - end else begin - if FSelectedIdx>=0 then begin - FOwnerDataItem.SetDataIndex(FSelectedIdx); - Result:=FOwnerDataItem; - end else - Result:=nil; end; end;