用鼠标拖拉就能改变ListBox里的数据的排列顺序,如何能实现呢?

解决方案 »

  1.   

    var
      Index: Integer;procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    begin
      Index:=TListBox(Source).ItemIndex;
      ListBox1.OnEndDrag:=ListBox1EndDrag;
      if State<>dsDragMove then
        Accept:=false;
    end;procedure TForm1.ListBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
    var
      Tmp: string;
    begin
      Tmp:=ListBox1.Items[ListBox1.ItemIndex];
      ListBox1.Items[ListBox1.ItemIndex]:=ListBox1.Items[Index];
      ListBox1.Items[Index]:=Tmp;
      ListBox1.OnEndDrag:=nil;
    end;end.你看这个效果怎么样?
    记得把DragMode属性设置成dmAutomatic哦。