| | | | Browse by category |
Problem
How can I drag item(s) from a listbox into the grid?
Cause
Action
Call AfxOleInit() in your Initinstance method and register the grid as drop target using CGXGridDropTarget::Register():
// Register the grid as drop target VERIFY(m_objDndDropTarget.Register(this, GX_DNDEGDESCROLL | GX_DNDAUTOSCROLL | GX_DNDTEXT /*| GX_DNDSTYLES |GX_DNDNOAPPENDCOLS|GX_DNDNOAPPENDROWS*/)); |
In your listbox override WM_LBUTTONDOWN:
void CToDoList::OnLButtonDown(UINT nFlags, CPoint point) { |
||||||
CListBox::OnLButtonDown(nFlags, point);
// Get current selection if (nCurSel != LB_ERR) |
||||||
// Get length of current selection int nLength = GetTextLen(nCurSel); if (nLength) |
||||||
// Allocate memory and get address to memory HGLOBAL hStr = GlobalAlloc(GMEM_FIXED | GMEM_SHARE, nLength+1); LPSTR pStr = (LPSTR)GlobalLock(hStr); if (pStr) |
||||||
GetText(nCurSel, pStr); GlobalUnlock(hStr); // Have to pass rectangle for now, // Cache the text data // Perform the drag and drop operation // remove the selection if |
||||||
DeleteString(nCurSel); | ||||||
// The OLE library eats the // button up message, make the // list box happy by simulating // another button up message. PostMessage(WM_LBUTTONUP, nFlags, MAKELONG(point.x, point.y)); |
||||||
} | ||||||
} | ||||||
} | ||||||
} |