Professional UI Solutions
Site Map   /  Register


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 » Grid D&D Collapse All
Subject Author Date
Rado Manzela Jun 1, 2010 - 6:30 AM

Can you provide some sample how to implement dragging text cell from one grid and drop it into another grid please? I cannot find anything like this in samples, I’ve tried to override OnGbwDataDndIsAllowed() and OnGbwDataDndDo() as suggested in FAQ, but I don’t have a clue how the implementation of OnGbwDataDndDo() should look like. I’ve hoped such trivial d&d will be done in default implementation, but it does nothing. Maybe because there seems to be some bug, because my OnGbwDataDndDo() is always called with  htInfo.m_nColNo = htInfo.m_nRowNo = -1 no matters which cell is selected/focused/dragged.

Thank you,

Technical Support Jun 2, 2010 - 10:34 AM

We recommend that you use the standard OLE drag-n-drop. It’s easy to use it. Prof-UIS is friendly with OLE drag-n-drop. When some OLE data object is drag-n-dropped over Prof-UIS tab items, then appropriate tab item becomes selected. This is related to MDI tabs, tabbed resizable bar groups and tab page container. This means you will be able to drop data into windows hidden in some non-selected tab page in some tabbed window container.
First of all, your app should initialize OLE. You will need to invoke AfxOleInit() or OleInitialize(). The CoInitialize() is not enough to start using OLE drag-n-drop APIs. The UI element or window which starts drag-n-dropping something is called drag-n-drop source (IOleDropSource, COleDropSource). The UI element or window which can accept drag-n-drop events (moving mouse over/in/out, dropping) is called drag-n-drop target (IOleDropTarget, COleDropTarget). You need two grid controls: one should implement drag-n-drop source, second is drag-n-drop target. You can implement both source and target in one grid control and you will be able to drag-n-drop from the grid control into the same grid control. Please note, the OLE drag-n-drop works between different running processes and between different threads of one app. If you need to limit its usage in scope of one UI thread of one process, then you should use your own registered clipboard format and generate its name using thread and process identifiers.
The CExtGridWnd grid control (and other derived from it grid controls) supports the OLE drag-n-drop (CExtGridWnd::OnGridDropSource***, CExtGridWnd::OnGridDropTarget***). The __EGWS_ADV_ENABLE_DATA_DND_DRAG|__EGWS_ADV_ENABLE_DATA_DND_DROP advanced flags applied with the CExtGridWnd::AdvModifyStyle() method will turn on the OLE drag-n-dropping feature in the CExtGridWnd grid control. The CExtGridWnd::m_strGridClipboardFormatName property allows you specify custom unique name for clipboard format. The grid control drag-n-drops abstract grid cell regions of any complexity. The cell regions are described using the CExtGR2D class. The grid control does not drag-n-drop text strings. It drag-n-drops regions of cell objects. When one or several grid cells are dropped, then the grid control creates instances of cells of the same type as cells which you stared drag-n-drop. The data of these cells are de-serialized from the OLE drag-n-drop data object. You can see the OLE drag-n-drop for abstract grid cell regions in the FormulaGrid sample application. The same abstract regions are supported for clipboard operations (CExtGridBaseWnd::m_dwSupportedAccelCommands, __EGSA_COPY|__EGSA_CUT|__EGSA_PASTE).
But if you would like to implement the OLE drag-n-drop from scratch, then please take a look at the source code of the FormEditor sample application. The toolbox objects can be drag-n-dropped from the toolbox window into the form editor window and into different object groups inside the same toolbox window. The toolbox customization window also implements the OLE drag-n-drop source.

Rado Manzela Jun 3, 2010 - 8:15 AM

Thank you for explaining. I’ve used your original D&D, but now I need to enable only DROPEFFECT_COPY and make it default. Setting cell to be read-only does not help, dragging will move it’s content. Maybe you could check for read-only flag of source cells while d&d.

I’ve solved this by overriding OnGbwDataDndDo() where I’ve copied complete code from your implementation and just changed one line to DROPEFFECT deAllow = DROPEFFECT_COPY;

But I’m nervous when copying code from parent class, do you think it is safe? I’m afraid your code will be changed in future releases and I’ll get some nasty bugs in my program after upgrade. Maybe you could query for allowed drop effect somewhere in next version.

Technical Support Jun 3, 2010 - 10:21 AM

The most correct way is to override the CExtGridWnd::OnGridDropTargetDragOver() virtual method and let the parent class method compute the DROPEFFECT value. If the computed value is DROPEFFECT_MOVE, then do not return it and just return DROPEFFECT_COPY instead. The parent class method assumes the DROPEFFECT_MOVE is the default effect. But if the Ctrl key is pressed, then it assumes the DROPEFFECT_COPY effect. This is the classic drag-n-dropping behavior.

Rado Manzela Jun 4, 2010 - 1:38 AM

Thank you, it works.