| | |
How to move a selected item up/down in List Box?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I don't think CListBox has a method to move a row from one spot to another. If you want to change the order of the items then I'd probably copy them all into a std::vector<std::string>, sort the vector however you want, delete everything from the list box, then copy the vector back in the order you want.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Yeah. There is no such function in the API too. But I don't know if the list box will flicker if you remove and add the items all at once. Can't you do it by using the
LB_SETITEMDATA message? I think it would be much faster. バルサミコ酢やっぱいらへんで
I don't know. It was just a hunch. I am too lazy to try it and see. Another straightforward way seems to be the use of LB_INSERTSTRING. Since you can specify the index of the position that you want to insert the string to, I think you can use it to change the order of the items.
バルサミコ酢やっぱいらへんで
This snippet sends the string at zero based index 3, to the position at index 0.
The original order of
cpp Syntax (Toggle Plain Text)
HWND hList = GetDlgItem(hwnd, IDC_LIST); char buf[100]=""; SendMessage(hList, LB_GETTEXT, (WPARAM)3, (LPARAM)buf); SendMessage(hList, LB_DELETESTRING, 3, 0); SendMessage(hList, LB_INSERTSTRING, 0, (WPARAM)buf);
0 1 2 3 4 5 will endup with 3 0 1 2 4 5 バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- [req]How to move elements in the list box up and down using command button? (Visual Basic 4 / 5 / 6)
- list box --php issue (PHP)
- Populating a fields on a form base on a selected item from a droplist. (PHP)
Other Threads in the C++ Forum
- Previous Thread: Reading multiple lines from a txt file
- Next Thread: Help with precision
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






