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).
Drag and Drop Row Reordering - MFC ListCtrlHow is it done?
Page 1 of 1
5 Replies - 2527 Views - Last Post: 04 August 2009 - 06:11 PM
Replies To: Drag and Drop Row Reordering - MFC ListCtrl
#2
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?
#3
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
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
#4
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
#5
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
#6
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.
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
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|