Link to home
Start Free TrialLog in
Avatar of pin_plunder
pin_plunder

asked on

How to move a lis item in a list view

well. I believe the title says it all.
I've added to buttons Up and Down, which I'm trying to let the user organize the items displayed in the list view.

Though I tried and tried I can't make it work. What can I do?

I would like source code please.

Thanks.
Avatar of DonBartholomew
DonBartholomew

You will have to do it 'manually'. It does not work if you don't set the focus ont the item after it is moved.


procedure TForm1.buttonUpClick(Sender: TObject);
var x: integer;
    s1, s2: string;
begin
  x := lstbox.ItemIndex;
  if x >= 1 then
    begin
      s1 := lstbox.Items.Strings[x];
      s2 := lstbox.Items.Strings[x-1];
      lstbox.Items.Strings[x] := s2;
      lstbox.Items.Strings[x-1] := s1;
      lstbox.ItemIndex := x-1;
    end;
end;
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pin_plunder

ASKER

thanks for your help