Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Drg & Drop in grid Collapse All
Subject Author Date
Offer Har Mar 25, 2007 - 7:55 PM

Dear Support,

Is there any support for drag&drop in the grid control?
I am looking for something like in a list-control & tree-control in which I can get an image of the cell dragged using CreateDragImage, and that image is attached to the cursor etc.

Regards,
Ron.

Technical Support Mar 26, 2007 - 12:30 PM

Here are two projects that demonstrate how you could implement drag-and-and drop in your grid windows:

test_tree_grid_idea_dnd.zip
TestGridStartDragNDrop.zip

Offer Har Mar 26, 2007 - 12:49 PM

Dear Support,

Thanks for the samples.
I need to be able to drop the dragged cell onto another window (view) which accepts the dragged items.

How can this be done?

Thanks,
Ron.

Technical Support Mar 27, 2007 - 7:31 AM

This task is partially related to the grid control. The grid control is only responsible to start the OLE drag-n-drop of appropriate data type (it’s called clipboard format in OLE drag-n-drop) and your view window is responsible to implement the IOleDropTarget interface, register itself as drop-target window and correctly handle drag-over and drop events. All these things are implemented in the FormEditor sample application where you can drop toolbox items into view windows and other toolbox groups. The toolbox window initiates the OLE drag-n-drop algorithm in the CFormEditorToolBoxWnd::OnToolBoxWndStartItemDrag() method with invoking of the oleDataSource.DoDragDrop() code and form view window handles OLE drag-n-drop events in three CFormEditorView::OnDrag***() virtual methods and one CFormEditorView::OnDrop() virtual method.

Your application should implement drag-n-drop source and target parts exactly in the same way. Nevertheless the CExtGridWnd class (and any derived from it) is not able to initiate OLE drag-n-drop, it supports the drag-n-drop starting event which is the CExtGridBaseWnd::OnGbwDataDndDo() method. To turn on invocations of this method you should override the CExtGridWnd::OnGbwDataDndIsAllowed() method and simply return true flag in it. The CExtGridWnd::OnGbwDataDndCanStart()virtual method allows you to disable drag-n-drop starting for particular grid cells.

Fortunately, you can serialize any grid cell including its run-time class information with MFC archives using the CExtGridCell::InstanceLoad() and CExtGridCell::InstanceSave() static methods. This allows you to put grid cells into OLE drag-n-drop data and even pass the grid cell objects between different processes. If you are going to implement the drag-n-drop in scope of one process only, then you can save only grid cell location and the clipboard format name should be based on the value which is unique for the current running copy of the process such as process identifier.