Click here to Skip to main content
15,904,926 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am able to re-order my list box items using a mouse. I am only using one listbox. The dialog has few combo boxes and other stuff too, so listbox is a child control of that Dialog.

For example I can drag and drop or move item5 to the 2nd position or to any position in the list using my mouse. However when I do that, I want my grid to get updated, the moment I finish performing that operation.

That is the moment the item5 goes to the second position, my grid should also get updated. I have tried using LBN_SELCHANGE, but it gets called before the listbox items reset to a new state, so the grid doesn't get updated to the new state although the listbox shows the re-ordering once the function ends.

I see when it gets called the listbox is still in its old state, and once it finishes then the change of state occurs. Actually none of the LBN functions are helpful in this case. I have tried using all of them.

I cant find any notification message function that shows the new list box state, that I can use to update my grid at the same moment as the list items move to a new position.

Any ideas on this will be appreciated. Thanks.
Posted
Updated 17-Feb-10 3:41am
v4

I could find a class in my MFC directory... :)

class CDragListBox : public CListBox
{
...
public:
  // Called when user releases mouse button to end drag event.
  virtual void Dropped(_In_ int nSrcIndex, _In_ CPoint pt);
...


BOOL CDragListBox::OnChildNotify(UINT nMessage, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	if (nMessage != m_nMsgDragList)
		return CListBox::OnChildNotify(nMessage, wParam, lParam, pResult);
	ASSERT(pResult != NULL);
	LPDRAGLISTINFO pInfo = (LPDRAGLISTINFO)lParam;
	ASSERT(pInfo != NULL);
	switch (pInfo->uNotification)
	{
	case DL_BEGINDRAG:
		*pResult = BeginDrag(pInfo->ptCursor);
		break;
	case DL_CANCELDRAG:
		CancelDrag(pInfo->ptCursor);
		break;
	case DL_DRAGGING:
		*pResult = Dragging(pInfo->ptCursor);
		break;
	case DL_DROPPED:
		Dropped(GetCurSel(), pInfo->ptCursor);
		break;
	}
	return TRUE;
}
 
Share this answer
 
v2
Thanks for the reply Eugen. I found the same thing so I am deriving a class from CDragListBox and overriding the virtual function Dropped() with the base class implementation and then adding the updating grid code to it once that is done.I hope it will work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900