Link to home
Start Free TrialLog in
Avatar of lapucca
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.
Avatar of rstaveley
rstaveley
Flag of United Kingdom of Great Britain and Northern Ireland image

You can use CComboBox's SetItemDataPtr/GetItemDataPtr to point to associated data.
Avatar of lapucca
lapucca

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.
Avatar of jkr
Qithout MFC, that would be like

wstring pwstr = new wstring;

*pwstr = "test";

SendMessage(hComboBox,CB_SETITEMDATA, nItemIndex, (LPARAM) pwstr);

However, you will need to take care of the pointers by deleting them later.
Avatar of lapucca

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.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial