Delphi TListview[3]实现拖拽功能
1、设置ListView1的属性:
?
1
|
Listview1 . DragMode:=dmAutomatic; |
2、OnDragOver事件:
?
1 2 3 4 5
|
procedure TForm1 . ListView1DragOver(Sender, Source: TObject; X, Y: Integer ; State: TDragState; var Accept: Boolean ); begin Accept := True ; end ; |
3、OnDragDrop事件:
?
1 2 3 4 5 6 7 8 9 10 11 12 13
|
procedure TForm1 . ListView1DragDrop(Sender, Source: TObject; X, Y: Integer ); var aItem, bItem: TListItem; begin if (Source is TListView) then begin bItem := (Source as TListView).Selected; aItem := (Source as TListView).Items . Insert((Source as TListView).Items . IndexOf((Source as TListView).GetItemAt(X, Y))); aItem . Assign(bItem); (Source as TListView).Selected . Delete; aItem . Selected := True ; end ; end ; |
赞 (0)