아브아카의 세상 빼꼼 바라보기

Delphi lisbox drag and drop 본문

컴퓨터/Delphi 코딩

Delphi lisbox drag and drop

아브아카 2015. 6. 17. 01:00

var StartingPoint : TPoint; implementation ... procedure TForm1.FormCreate(Sender: TObject) ; begin ListBox1.DragMode := dmAutomatic; end; procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); var ListBox: TListBox; i, TargetIndex: Integer; SelectedItems: TStringList; begin Assert(Source=Sender); ListBox := Sender as TListBox; TargetIndex := ListBox.ItemAtPos(Point(X, Y), False); if TargetIndex<>-1 then begin SelectedItems := TStringList.Create; try ListBox.Items.BeginUpdate; try for i := ListBox.Items.Count-1 downto 0 do begin if ListBox.Selected[i] then begin SelectedItems.AddObject(ListBox.Items[i], ListBox.Items.Objects[i]); ListBox.Items.Delete(i); if i<TargetIndex then dec(TargetIndex); end; end; for i := SelectedItems.Count-1 downto 0 do begin ListBox.Items.InsertObject(TargetIndex, SelectedItems[i], SelectedItems.Objects[i]); ListBox.Selected[TargetIndex] := True; inc(TargetIndex); end; finally ListBox.Items.EndUpdate; end; finally SelectedItems.Free; end; end; end; procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean) ; begin Accept := Source = ListBox1; end; procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) ; begin StartingPoint.X := X; StartingPoint.Y := Y; end;



출처 : http://stackoverflow.com/questions/9176684/delphi-listbox-drag-drop-multiple-items

'컴퓨터 > Delphi 코딩' 카테고리의 다른 글

Delphi Lite  (0) 2018.04.17
델파이 stringlist Natural Order 정렬하기  (0) 2015.08.05