
09.11.2012, 16:54
|
 |
Профессионал
|
|
Регистрация: 06.08.2012
Адрес: Кривой Рог
Сообщения: 1,791
Версия Delphi: Delphi 7, XE2
Репутация: 4415
|
|
Можно сделать примерно так:
Код:
var
OldIndex: Integer;
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
NewIndex, i1, i2, DiffIdx, Direct: Integer;
begin
case State of
dsDragEnter: OldIndex := ListBox1.ItemAtPos(Point(X, Y), True);
dsDragMove:
begin
NewIndex := ListBox1.ItemAtPos(Point(X, Y), True);
DiffIdx := NewIndex - OldIndex;
if DiffIdx < 0 then
begin
i1 := 0;
Direct := +1;
end else
begin
i1 := ListBox1.Items.Count - 1;
Direct := -1;
end;
ListBox1.Items.BeginUpdate;
try
while (i1 >= 0) and (i1 < ListBox1.Items.Count) do
begin
if ListBox1.Selected[i1] then
begin
i2 := i1 + DiffIdx;
if (i2 < 0) or (i2 >= ListBox1.Items.Count) then Break;
ListBox1.Items.Move(i1, i2);
ListBox1.Selected[i2] := True;
end;
i1 := i1 + Direct;
end;
finally
ListBox1.Items.EndUpdate;
end;
OldIndex := NewIndex;
end;
end;
end;
|