944,110 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4603
  • C++ RSS
Jul 10th, 2007
0

How to move a selected item up/down in List Box?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
driplet is offline Offline
28 posts
since Jul 2007
Jul 10th, 2007
0

Re: How to move a selected item up/down in List Box?

How about looking at the facilities offered by the API?
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 10th, 2007
0

Re: How to move a selected item up/down in List Box?

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 11th, 2007
0

Re: How to move a selected item up/down in List Box?

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.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 11th, 2007
0

Re: How to move a selected item up/down in List Box?

Why would he want to use LB_SETITEMDATA ? That will not change the order of the items that appear in the list box.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 11th, 2007
0

Re: How to move a selected item up/down in List Box?

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.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 11th, 2007
0

Re: How to move a selected item up/down in List Box?

Yes, LB_INSERTSTRING will work if all he wants to do is insert the new item in a specific location.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 11th, 2007
0

Re: How to move a selected item up/down in List Box?

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?
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 11th, 2007
0

Re: How to move a selected item up/down in List Box?

Changing the order of the items is what the OP wants to do.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Jul 12th, 2007
0

Re: How to move a selected item up/down in List Box?

This snippet sends the string at zero based index 3, to the position at index 0.
cpp Syntax (Toggle Plain Text)
  1. HWND hList = GetDlgItem(hwnd, IDC_LIST);
  2. char buf[100]="";
  3. SendMessage(hList, LB_GETTEXT, (WPARAM)3, (LPARAM)buf);
  4. SendMessage(hList, LB_DELETESTRING, 3, 0);
  5. 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
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Reading multiple lines from a txt file
Next Thread in C++ Forum Timeline: Help with precision





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC