
November 14th, 2012, 08:51 AM
|
|
Contributing User
|
|
Join Date: Mar 2007
Posts: 230
Time spent in forums: 4 Days 20 h 39 m
Reputation Power: 7
|
|
|
Moving listview with columns items up/down with buttons
I have a listview with columns, and I try to move a single selected item (row selected) up or down, but nothing happends, not even an error message.
The multiselect from the listview is set to False.
Here is the code I have, it does work when I don't have multiple columns:
Code:
procedure TForm1.upbtnClick(Sender: TObject);
var
Index: integer;
temp : TListItem;
begin
if ListView1.Focused then
if ListView1.SelCount>0 then
begin
//ListView1.ReadOnly := False;
Index := ListView1.Selected.Index;
if Index>0 then
begin
temp := ListView1.Items.Insert(Index-1);
temp.Assign(ListView1.Items.Item[Index+1]);
ListView1.Items.Delete(Index+1);
// fix display so moved item is selected/focused
ListView1.Selected := temp;
ListView1.ItemFocused := temp;
end;
//ListView1.ReadOnly := True;
end;
end;
procedure TForm1.downbtnClick(Sender: TObject);
var
Index: integer;
temp : TListItem;
begin
if ListView1.Focused then
if ListView1.SelCount>0 then
begin
//ListView1.ReadOnly := False;
Index := ListView1.Selected.Index;
if Index<ListView1.Items.Count then
begin
temp := ListView1.Items.Insert(Index+2);
temp.Assign(ListView1.Items.Item[Index]);
ListView1.Items.Delete(Index);
// fix display so moved item is selected/focused
ListView1.Selected := temp;
ListView1.ItemFocused := temp;
end;
//ListView1.ReadOnly := True;
end;
end;
Thanks
|