5 Replies - 3209 Views - Last Post: 04 August 2009 - 06:11 PM Rate Topic: -----

#1 dwayne  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 02-August 08

Drag and Drop Row Reordering - MFC ListCtrl

Posted 02 August 2009 - 10:27 AM

I need to be able to reorder items in a ListCtrl by dragging them into position. The ListCtrl will be in report view all the time and it will not need to accept any files that get dropped on the window. This is just for reordering the rows IN the application. I will also need to retrieve the positions of all the items later but I can handle that. If anyone needs my code posted, I will do so. But right now it is a barebones GUI and as it is dialog based I don't see how code could help or prove this isn't homework (which it isn't).

Is This A Good Question/Topic? 0
  • +

Replies To: Drag and Drop Row Reordering - MFC ListCtrl

#2 dwayne  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 02-August 08

Re: Drag and Drop Row Reordering - MFC ListCtrl

Posted 04 August 2009 - 10:34 AM

Is this possible, or does no one know how it is done?
Was This Post Helpful? 0
  • +
  • -

#3 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 966
  • Joined: 09-May 09

Re: Drag and Drop Row Reordering - MFC ListCtrl

Posted 04 August 2009 - 11:36 AM

Im sure this can be done some how

try right clicking on your list contol and select "add event handler"
im not at a compiler now but im sure theres a "getCurSel()"

this simply allows you to control what happens when the user selcts an item.
get current selection :)

This method is controled by an index, im sure it must be as simple as updating the index to adjust the position

Have a google into getCurSel() method

Hope this progress you a little further
Kevin

Keep posting whne you have attempted a little code, ill try and help

This post has been edited by deery5000: 04 August 2009 - 11:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 dwayne  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 02-August 08

Re: Drag and Drop Row Reordering - MFC ListCtrl

Posted 04 August 2009 - 01:12 PM

I am aware of the getCurSel() method (and I find MSDN to be the best help) and I can make buttons do the reordering, I just can't implement drag and drop. I'll try to condense my code a bit (get rid of the GUI stuff) and post some code (or just link to the whole project). Thanks.

This post has been edited by dwayne: 04 August 2009 - 01:18 PM

Was This Post Helpful? 0
  • +
  • -

#5 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Drag and Drop Row Reordering - MFC ListCtrl

Posted 04 August 2009 - 01:53 PM

getcursel() just gets cursor selection in listbox, i would just add a up and down button to move items.

void dialog::onBnClickedUp()
{
   int pos = list.GetCurSel();
   CString text;
   list.GetText(pos,text);
   list.DeleteString(pos);
   list.InsertString(pos-1,text);
   list.getCurSel(pos-1);
}

void dialog::onBnClickedDown()
{
   int pos = list.GetCurSel();
   CString text;
   list.GetText(pos,text);
   list.DeleteString(pos);
   list.InsertString(pos+1,text);
   list.getCurSel(pos+1);
}



This post has been edited by ImaSexy: 04 August 2009 - 01:54 PM

Was This Post Helpful? 0
  • +
  • -

#6 dwayne  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 02-August 08

Re: Drag and Drop Row Reordering - MFC ListCtrl

Posted 04 August 2009 - 06:11 PM

I guess I'll just do that until I figure out or someone makes a way to do this. And I don't think your method will work for me, though you couldn't of known without my code, but I use the LVITEM structure to input and retrieve as well as modify data (easier when working with files and directories). So with a couple modifications, your code will work. So it's actually just a matter of loading the item back into a LVITEM structure and them setting the "lvItem.pszItem = pos". Thanks.

EDIT: Acutally, GetCurSel() is for a ListBox and not a ListCtrl. I have to use GetSelectionMark() to retrieve the selected item and then I get set the position, I think.

This post has been edited by dwayne: 04 August 2009 - 06:55 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1