procedure
ListViewItemMoveUpDown(lv: TListView; Item: TListItem; MoveUp, SetFocus:
Boolean);
var
DestItem:
TListItem;
begin
if (Item = nil) or
((Item.Index - 1 < 0) and MoveUp) or
((Item.Index + 1 >= lv.Items.Count) and
(not MoveUp))
then
Exit;
lv.Items.BeginUpdate;
try
if MoveUp then
DestItem
:= lv.Items.Insert(Item.Index - 1)
else
DestItem
:= lv.Items.Insert(Item.Index + 2);
DestItem.Assign(Item);
lv.Selected
:=
DestItem;
Item.Free;
finally
lv.Items.EndUpdate;
end;
if SetFocus then
lv.SetFocus;
DestItem.MakeVisible(False);
end;
procedure TForm1.Button3Click(Sender:
TObject);
begin
ListViewItemMoveUpDown(ListView1,
ListView1.Selected, True, True);//ÉÏÒÆ
end;
procedure TForm1.Button4Click(Sender:
TObject);
begin
ListViewItemMoveUpDown(ListView1,
ListView1.Selected, False, True);//ÏÂÒÆ
end;