TcxCustomGridView.OnDragDrop Event
Occurs when a user drops the object being dragged within the current View.
Declaration
property OnDragDrop: TDragDropEvent read; write;
Remarks
Handle the OnDragDrop event to perform actions when a user drops the object being dragged within the current View. The Source parameter represents the object being dropped and the Sender parameter indirectly refers to the current View. The X and Y parameters are the coordinates of the mouse positioned over the View.
Grid Views are not controls (i.e. do not descend from TControl), so they cannot receive keyboard and mouse messages and thus cannot be involved in drag-and-drop directly. To overcome this problem, grid Views are placed onto grid sites (TControl descendants), which interact with the user and pass appropriate messages to Views. A grid site is an object of the TcxGridSite class. The View owned by a site is addressed by the TcxGridSite.GridView property.
In drag-and-drop operations, grid Views are represented by their grid sites. The Sender parameter identifies the grid site containing the current View.
If the source of a drag-and-drop operation is a grid View, the Source parameter refers to a TcxDragControlObject object with the Control property set to a grid site. If the source is a grid control itself, the Source parameter is still a TcxDragControlObject object, but its Control property refers to the TcxGrid object.
You can use the following code to get the grid View which is the source of a drag-and-drop operation:
procedure TForm1.tvTargetDragDrop(Sender, Source: TObject; X, Y: Integer);
var
ADroppedView: TcxCustomGridView;
begin
if Source is TcxDragControlObject then
with TcxDragControlObject(Source) do
if Control is TcxGridSite then
with TcxGridSite(Control) do
begin
ADroppedView := GridView;
//...
end;
end;
To implement drag-and-drop, you need to handle the OnDragOver event as well. Use this event to decide whether drag-and-drop is possible at a given point.