现在实现了两个listbox的相互拖拽 怎么实现禁止他们的自身拖拽?

解决方案 »

  1.   

      Accept := (Source <> Sender) and (Source Is TListBox)
      

  2.   


       if ((Source Is TFileListBox) and (Source  <> Sender))  or ((Source Is TDirectoryListBox) and (Source  <> Sender)) then
         Accept:=True;  // accept drag operation我这样写 还是可以自身拖拽啊
      

  3.   

    1:将两个Listbox的DragMode属性设为dmAutomatic. 2:在Listbox1的onDragOver事件中写入: 
    Delphi(Pascal) code
    procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    begin
       if Sender is TListBox then
      Accept:=true;
    end;
    3:在Listbox1的onDragDrop事件中写入: 
    Delphi(Pascal) code
    procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    begin
     TListBox(sender).Items.Add(TListBox(Source).Items[TListBox(Source).itemindex]);
     TListBox(Source).Items.Delete(TListBox(Source).itemindex);
    end;
    4:Listbox2的onDragOver事件指向Listbox1的onDragOver事件,onDragDrop事件指向Listbox1的onDragDrop的事件.
      

  4.   

    1:将两个Listbox的DragMode属性设为dmAutomatic.  2:在Listbox1的onDragOver事件中写入: procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; 
      State: TDragState; var Accept: Boolean); 
    begin 
       if Sender is TListBox then 
      Accept:=true; 
    end; 3:在Listbox1的onDragDrop事件中写入: procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); 
    begin 
     TListBox(sender).Items.Add(TListBox(Source).Items[TListBox(Source).itemindex]); 
     TListBox(Source).Items.Delete(TListBox(Source).itemindex); 
    end; 
    4:Listbox2的onDragOver事件指向Listbox1的onDragOver事件,onDragDrop事件指向Listbox1的onDragDrop的事件.
      

  5.   

    to GDTOPONE   
    我拖拽已经实现了 
    只是要禁止自身拖拽而已