Форум: "Основная";
Текущий архив: 2002.04.18;
Скачать: [xml.tar.bz2];
Внизdrag n drop Найти похожие ветки
← →
anod (2002-04-05 14:04) [0]Пытаюсь в 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:22) [1]у тебя nsender и nsource - один и тот же
принимающую позицию определяй по ItemAtPos
← →
anod (2002-04-05 14:23) [2]Ну, я это понял. А как определить Source.
← →
MBo (2002-04-05 14:24) [3]sorry, про один и тот же - в случае переноса в одном боксе.
← →
anod (2002-04-05 14:35) [4]А, если бы у меня было 2 бокса, тогда работал бы Source?
← →
MBo (2002-04-05 14:47) [5]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;
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2002.04.18;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.005 c