![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
drag n drop [D6, Win2k]
anod © (2002-04-05 14:04:00)Пытаюсь в TListBox реализовать Drag"n"Drop, немного не понимаю.
procedure TForm1.DirListDragDrop(Sender, Source: TObject; X, Y: Integer);
var nsource,nsender,i:byte; s,s1:string; doparr:array of string;
begin
nsource:=(Source as TListBox).ItemIndex; //get source index
nsender:=(Sender as TListBox).ItemIndex; //get sender index
s:=d[nsource];
setlength(doparr, length(d));
for i:= 0 to length(d)-1 do doparr[i]:=d[i];
for i:= 0 to length(d)-1 do if i<>nsource then d[i]:=doparr[i];
for i:= nsender to length(d)-1 do
begin
s1:=d[i];
d[i]:=s;
s:=s1;
end;
UpdateDirList; //Отчищяю ListBox и записываю массив D.
end;
Переносит только на 1 позицию. Думаю Source неправильно определяю.
MBo (2002-04-05 14:47:00) [1]procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=Sender=ListBox1;
end;
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var pt:TPoint;
s:string;
begin
pt.x:=x; pt.y:=y;
s:=ListBox1.items[ListBox1.ItemIndex];
ListBox1.Items.Delete(ListBox1.ItemIndex);
ListBox1.Items.Insert(ListBox1.ItemAtPos(pt,true),s);
end;
anod (2002-04-05 14:35:00) [2]А, если бы у меня было 2 бокса, тогда работал бы Source?
MBo (2002-04-05 14:24:00) [3]sorry, про один и тот же - в случае переноса в одном боксе.
anod (2002-04-05 14:23:00) [4]Ну, я это понял. А как определить Source.
MBo (2002-04-05 14:22:00) [5]у тебя nsender и nsource - один и тот же
принимающую позицию определяй по ItemAtPos