procedure TForm1.ListView1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
const
RowHeightDefault = 14;
procedure SetListViewIndex(Sig: Integer);
var RowHeightDefault,RowHeight,LVClientHeight,LVClientRowCount,NewIndex: Integer;
begin
if (Sender
as TListView).ViewStyle=vsReport
then begin
if (Sender
as TListView).Items.Count>0
then begin
// Zeilenhöhe ermitteln
// wenn ListView.CheckBoxes=True Standardzeilenhöhe=17
if (Sender
as TListView).Checkboxes
then RowHeightDefault:= 17
// sonst Standardzeilenhöhe=14
else RowHeightDefault:= 14;
// wenn eine ImageList verknüpft wurde
if Assigned((Sender
as TListView).SmallImages)
then begin
RowHeight:= (Sender
as TListView).SmallImages.Height;
if RowHeight<RowHeightDefault
then RowHeight:= RowHeightDefault;
end
// sonst Standardzeilenhöhe
else RowHeight:= RowHeightDefault;
// ClientHeight minus Rahmen
LVClientHeight:= (Sender
as TListView).ClientHeight-2;
// ClientHeight ggf. minus Spaltenüberschrift
if (Sender
as TListView).ShowColumnHeaders
then
Dec(LVClientHeight,17);
// Anzahl voll sichtbarer Elemente minus eins
LVClientRowCount:= (LVClientHeight
div RowHeight)-1;
// neuer theoretischer Index
NewIndex:= (Sender
as TListView).ItemIndex+(LVClientRowCount*Sig);
// theoretischer Index bereinigen
if NewIndex>=(Sender
as TListView).Items.Count
then
NewIndex:= (Sender
as TListView).Items.Count-1;
if NewIndex<0
then NewIndex:= 0;
// neues Item anzeigen
(Sender
as TListView).ItemIndex:= NewIndex;
(Sender
as TListView).Items[NewIndex].Focused:= True;
(Sender
as TListView).Items[NewIndex].MakeVisible(True);
end;
Key:= 1;
end;
end;
begin
case Key
of
VK_PRIOR: SetListViewIndex(-1);
// Bild-aufwärts-Taste
VK_NEXT: SetListViewIndex(1);
// Bild-abwärts-Taste
end;
end;