0

Hi guys:

I am using Borland C++ Builder to make a window application. I need to use a list box to display the items I selected. Besides, I need to chang the order of the selected items in the box. Could any body please give me a clue how I can do this?

Thanks in advance!

Doug

3
Contributors
9
Replies
13
Views
10 Years
Discussion Span
Last Post by WolfPack
0

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.

0

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.

Edited by happygeek: fixed formatting

0

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.

0

Yeah. But won't deleting an item from it's original location and inserting it in it's new location change the order of the items?

1

This snippet sends the string at zero based index 3, to the position at index 0.

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);

The original order of 0 1 2 3 4 5 will endup with 3 0 1 2 4 5

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.