Listbox design question.

Started by
5 comments, last by GetWindowRect 18 years, 8 months ago
I am writing a wrapper class for a listbox. In the listbox I want each item to have a 2 text values. I want to have 1 of the text values to go into the listbox as normal, but I want to be able to select out a different value than what is displayed. For example. I am playing around with c++ trying to make an MP3 player. As of now, I have the filename in a listbox and you can select an item and play it. However it is the whole file location. I would like to somehow just display the song, yet have it hold the file location in a hidden array/vector so I could select it out for the selected item. The question is, what would be the best way of going about this. I have rarely used vectors, but I could make a vector of char* or strings, and each time an item is added into the listbox, put the value to be selected in the vector, the problems with this method are: 1) If the listbox is sorted how could I "sort" the items in the vector according to the listbox, rather than by the items in the vector. 2) How would I be able to tell which item in the vector to remove when an item in the listbox is deleted. I am sure I could think of more problems but those are just examples. Is there an easier method to go about doing this, or any ideas? Thanks in advance
Advertisement
duh... give it up. nothing's simpler than subclassing an mfc class
DUH handle all the standard messages to be handled in the base class
Quote:duh... give it up. nothing's simpler than subclassing an mfc class

I don't want to use the MFC or subclass any of its classes.

Quote:Original post by Anonymous Poster
DUH handle all the standard messages to be handled in the base class

handle the messages to do what? I still need to store the value somewhere, or am I missing what you mean? If you insist on saying "DUH", try to make a post that makes a little more sense, I already handle all the adding through my class, my question is how would I store the second text value in order to be retrieved again.

Thanks anyway.
You can use the item data of every item to store a value or a pointer to a struct. More specifically, look into the functions SetItemData and GetItemData.

Use that item data to find the pairs of display text and actual item value.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thank you Endurion for the reply, although the only SetItemData/GetItemData functions I can find are for the MFC which I am not using, I am using Win32 API to learn how things work. If I am incorrect please let me know, otherwise I will keep looking for a solution.
Nevermind my last post, I found LB_SETITEMDATA and LB_GETITEMDATA messages that I can use with SendMessage, I will look into how to use them correctly, thank you again Endurion. Much appreciated.

This topic is closed to new replies.

Advertisement