0

Possible Duplicate:
Delphi: Shift-Up and Shift-Down in the Listview

Hi I have a list view and I want to be able to move the selected item / items up and down the list using buttons but cannot figure out how to do this, Could someone give me an example

many thanks

Colin

Community
  • 1
  • 1
colin
  • 2,983
  • 6
  • 41
  • 49

1 Answers1

6
procedure Tfrprodetile.ExchangeItems(lv: TListView; const i, j: Integer);
var
  tempLI: TListItem;
begin
  lv.Items.BeginUpdate;
  try
    tempLI := TListItem.Create(lv.Items);
    tempLI.Assign(lv.Items.Item[i]);
    lv.Items.Item[i].Assign(lv.Items.Item[j]);
    lv.Items.Item[j].Assign(tempLI);
    tempLI.Free;
  finally
    lv.Items.EndUpdate
  end;
end;

and for use :

move down :

ExchangeItems(lst_detile,lst_detile.Selected.Index,lst_detile.Selected.Index+1);

move up :

ExchangeItems(lst_detile,lst_detile.Selected.Index,lst_detile.Selected.Index-1);

note that "lst_detile" is name of my listview

good day !

mohsen
  • 61
  • 5