Skip to main content

Example: Starting Drag-And-Drop Manually

The following example shows how you can start drag-and-drop manually within the tvCustomers View by handling its OnMouseDown event. To start a drag-and-drop operation for a View, you should call the BeginDrag method of the View’s grid site object (the BeginDrag method is inherited from the TControl class). The grid site (TcxGridSite) represents the control which contains and displays the View. It is passed as the Sender parameter to the OnMouseDown event. Note: the grid site can also be accessed via the View’s Site property.

To enable starting drag-and-drop manually, you should set the View’s DragMode property to dmManual.

The following OnMouseDown handler starts drag-and-drop if the user clicks within a grid record.

procedure TForm1.tvCustomersMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  with TcxGridSite(Sender) do
  begin
    if ViewInfo.GetHitTest(X, Y).HitTestCode = htRecord then
      BeginDrag(False);
  end;
end;