lapucca
asked on
Is there a way to store 2 wstring values to each list item of a comboBox in a COM project?
Hi, I read in a name field and a description field for each list item of a comboBox on my Dialog page. I want to display only the name in the Combobox but I want to be able to get its coorsponding despcritpion in the code. Do I need to buid an array and deal with that each time my code need the descrption field of a selected name in the comboBox or is there a way to store it and access it easiy from the comboBox. I know C# .net 's comboBox offers this feature but what about C++ comboBox? Thanks.
You can use CComboBox's SetItemDataPtr/GetItemData Ptr to point to associated data.
ASKER
I'm not using MFC in my project. Can you show an example or a url for a example how I can do this? Thank you.
Qithout MFC, that would be like
wstring pwstr = new wstring;
*pwstr = "test";
SendMessage(hComboBox,CB_S ETITEMDATA , nItemIndex, (LPARAM) pwstr);
However, you will need to take care of the pointers by deleting them later.
wstring pwstr = new wstring;
*pwstr = "test";
SendMessage(hComboBox,CB_S
However, you will need to take care of the pointers by deleting them later.
ASKER
Thank you But I don't understand why I need to use "new" for the wstring pwstr. Doesn't wstring manages it's own memory allocat and de-allocate?
Oh, Is this becuase the memory is allocated until I'm done with this. Like I can release this at the end in my desctructor module. How do I delete a wstring? So far, I have let it manage its own memory.
Thank you.
Oh, Is this becuase the memory is allocated until I'm done with this. Like I can release this at the end in my desctructor module. How do I delete a wstring? So far, I have let it manage its own memory.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.