Hi there. I am looking to be able to load the contents of combo boxes at runtime. For example, in our code when we want to populate a combo box, we fill in a vector of strings and pass it to the GUI code, which then adds them.. (Our GUI is localized; there are two versions of everything: "external" for the GUI, "internal" to be stored internally. We also use plugins, where the available settings from plugin to plugin might be different.)
How hard would it be to rewrite/adapt the code (assuming I do it) to make this possible? One method that comes to mind would be to change the code so that rather than store a class type in the dialog data, we store an abstract id, that can be resolved to a class type plus a specific instance of that class, which we could invoke to add strings directly (using an extended interface)..
To add strings at runtime to a combo box just use CComboBox::AddString. If you mean in combination with my TreeOptionsctrl, then look at the sample which comes with it, specifically the "CDowComboBox" class.
As regards localisation, all the strings which the class uses are taken from string table resources, so you should just need to translate these.
I want to be able to reuse CDowComboBox for two completely different combo boxes, each with different available settings. So imagine I add a parameter to the constructor (or whereever), passing a vector of strings, which would then be consumed in the Create() function to build the combo box content. Can this be done?
Bonus question: How would I completely clear out the strings from an existing combo box, and readd different strings? (Some controls filter the content displayed in other controls.)
Note that the CTreeOptionsCombo object would be owned by the caller, not by the CTreeOptionsCtrl. At the moment, this blows up because the CTreeOptionsCtrl is still expecting to create the object. It would be best if I could take ownership of the object, though, so I can invoke the normal MFC combo box API when I need to. (To add or remove strings, change the selection, change the drop width, etc.)
Perhaps instead of this: m_ctrlTree.AddComboBox(HTREEITEM, myCombo1.GetRuntimeClass());
do this instead (after the necessary changes, of course)? m_ctrlTree.AddComboBox(HTREEITEM, &myCombo1);
int CDowComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
//Let the base class do its thing
if (CListOptionsCombo::OnCreate(lpCreateStruct) == -1)
//Get the ListOptionsCtrl item data
CListOptionsItemData* pItemData = (CListOptionsItemData*)m_pListCtrl->GetItemData(m_nListCtrlIndex);
//Cast this controls item data back to a CStringArray
CStringArray* pNames = (CStringArray*)pItemData->m_dwItemData;
for (int nIndex = 0; nIndex < pNames->GetSize(); nIndex++)
Bonus Question Answer: If you use the above mechanism then whenever you change what is in "some_stack_based_CStringArray" somewhere else in your code, then these changes will be reflected into the combo box when it is recreated.
Last Visit: 31-Dec-99 19:00 Last Update: 24-Dec-14 13:33