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 General Discussion » Drag and drop grid cells Collapse All
Subject Author Date
Anthony Spring Oct 4, 2006 - 10:06 AM

I’m trying to implement a situation where the order of grid cells can be changed by clicking and dragging them up or down.

I’ve noticed that there seems to be drag and drop support for outter grid cells, but not for the inner cells themselves.

Is there a simple way for me to get drag and drop events for a cell such as CExtGridCellString?

My current ideas include modifying the cell type to watch the click events and use the hover events to track the movement of the mouse and eventually report it back to the main interface, however that is nowhere near an elegant solution.

Thanks.

Technical Support Feb 5, 2008 - 11:58 AM

The OnGbwDataDndDo() virtual method is invoked for executing a drag-n-drop algorithm. You can implement your own drag-n-drop algorithm based on the message loop in this method. You can use an OLE drag-n-drop algorithm which is much more easier and convenient. In any case you will need to invoke the HitTest() method but you don’t need to override it. The FormEditor sample does not use a grid window but it implements OLE drag-n-drop and you can take a look at it for details.

Bart Kampers Feb 5, 2008 - 4:25 AM

I implemented this:

bool CStructureTreeGrid::OnGbwDataDndIsAllowed() const
{
ASSERT_VALID(this);
TRACE(_T("CStructureTreeGrid::OnGbwDataDndIsAllowed\r"));
return true;
}


bool CStructureTreeGrid::OnGbwDataDndCanStart(const CExtGridHitTestInfo & htInfo)
{
ASSERT_VALID(this);
__super::OnGbwDataDndCanStart(htInfo);
TRACE(_T("CStructureTreeGrid::OnGbwDataDndCanStart(%d,%d)\r"), htInfo.m_nColNo, htInfo.m_nRowNo);
return true;
}


void CStructureTreeGrid::OnGbwDataDndDo(const CExtGridHitTestInfo & htInfo)
{
    ASSERT_VALID(this);
__super::OnGbwDataDndDo(htInfo);
TRACE(_T("CStructureTreeGrid::OnGbwDataDndDo(%d,%d)\r"), htInfo.m_nColNo, htInfo.m_nRowNo);
}


When I press down the mouse button on a cell see on the output:

CStructureTreeGrid::OnGbwDataDndIsAllowed
CStructureTreeGrid::OnGbwDataDndCanStart(1,1)


When I start dragging I immediately see:

CExtGridBaseWnd::OnGbwDataDndDo(1,1)
CStructureTreeGrid::OnGbwDataDndDo(1,1)


When I release the mouse button I only see:

CStructureTreeGrid::OnGbwDataDndIsAllowed


This gives me no information about the cell where I released the button. Should I ovverride ::HitTest?



In CExtGridBaseWnd::OnLButtonUp ther is a clause "if ( OnGbwDataDndIsAllowed() && m_eMTT == __EMTT_DATA_DND_STARTING )" but this condition is never met.

Technical Support Feb 4, 2008 - 12:35 PM

You don’t need to handle any WM_*** mouse messages. You should do the following:

1) Required task. Override the CExtGridBaseWnd::OnGbwDataDndIsAllowed() virtual method and simply return true from it. This step is right. This will make the grid window detecting short mouse shift after left mouse click on inner data cell.

2) Optional task. The CExtGridBaseWnd::OnGbwDataDndGetStartOffset() virtual method returns a shift in pixels which should be assumed as drag-n-drop starting. You can override it to make this shift larger or smaller.

3) Optional task. The CExtGridBaseWnd::OnGbwDataDndCanStart() virtual method is invoked for checking whether drag starting event is allowed for specified cell location. You can override this method if some grid cells should not be enabled for drag-n-dropping.

4) Required task. The CExtGridBaseWnd::OnGbwDataDndDo() virtual method is invoked for performing drag-n-drop.

The grid controls invokes first three methods before invoking last one. But typically only fist and last methods should be overridden. Please also note, all the CExtGridCell*** grid cell classes are serializeable including run-time class information. You can use the CExtGridCell::InstanceLoad() and CExtGridCell::InstanceSave() static methods for serializing grid cells within their run time types. Serialized data can be part of OLE drag-n-drop data registered as specific for your application clipboard format. So, drag-n-dropping and copying/pasting task can be coded both at once.

Bart Kampers Feb 4, 2008 - 10:09 AM

So I must override

- CExtTreeGridWnd::OnGbwDataDndIsAllowed : return true
- CExtTreeGridWnd::OnGbwDataDndDo : decide whether dragging is allowed for a particular cell, indicate that dragging has begun
- CWnd::OnLButtonUp : perform drop actions

Right?

Technical Support Oct 5, 2006 - 9:41 AM

We did not implement drag-and-drop for inner cells in the CExtGridWnd class because this feature can be absolutely different depending on grid types and their selection models. But there are some methods in the grid that may be helpful if you decide to implement this yourself. The CExtGridWnd class supports the event when drag-and-drop of inner data cells starts. The OnGbwDataDndIsAllowed() virtual method returns true if a data cell can be drag-and-dropped. The OnGbwDataDndCanStart()virtual method detects whether a particular clicked data cell can be drag-n-dropped. The OnGbwDataDndDo() virtual method is invoked to perform your particular drag-and-drop algorithm.

Anthony Spring Oct 10, 2006 - 3:25 PM

Thanks that worked beautifully. :)