Delphi 1
Drag & Drop между двумя компонентами ListBox
Вот пересмотренный OnDragDrop, использующий source (источник) и sender (передатчик) вместо DstList и SrcList. Теперь, если вы установили SrcList и DstList для использования тех же методов OnDragOver и OnDragDrop и создали обработчик события OnDragDrop, то для операции Drag and Drop вы можете использовать оба решения.
procedure TDualListDlg.DstListDragDrop(Sender, Source: TObject; X, Y: Integer);
vardroppedOnIndex: integer;
anItem: integer;
numberOfItems: integer;
beginif (Sender is TListbox) and (Source is TListBox) then begin droppedOnIndex := TListBox(Sender).ItemAtPos(Point(X,Y),false);
numberOfItems := TListBox(Source).SelCount;
anItem := 0;
while numberOfItems > 0 do
begin
if TListBox(Source).Selected[anItem] = true then
begin
TListBox(Sender).Items.Insert(droppedOnIndex,TListBox(Source).Items[anItem]);
TListBox(Source).Items.Delete(anItem);
TListBox(Source).Update;
TListBox(Sender).Update;
numberOfItems := numberOfItems - 1;
end
else
anItem := anItem + 1;
end;
end;end; |
Для того, чтобы предотвратить операцию Drag and Drop с одним и тем же компонентом, используйте следующий код в обработчике события OnDragOver:
if (Sender is TListBox) and (Source is TListBox) then begin
if TListBox(Sender).Name = TListBox(Source).Name then
Accept := False
else
Accept := true;
end
|
[000445]