MFC RIbbon - Multiple CMFCRibbonComboBox on the same panel, respond to selectitem action performed on any onComboBox
-
01-06-2021 - |
Pregunta
I have 2 CMFCRibbonComboBox on the same Panel in a Ribbon- Eg:
CMFCRibbonComboBox *individualComputers =
new CMFCRibbonComboBox(-1,FALSE, 100, "Individual Computers", -1);
individualComputers->AddItem("Computer 1");
individualComputers->AddItem("Computer 2");
individualComputers->AddItem("Computer 3");
individualComputers->SelectItem(0);
CMFCRibbonComboBox * groupNames =
new CMFCRibbonComboBox (-1, FALSE, 100, "Computer Group Names", -1);
groupNames->AddItem("GROUP 1");
groupNames->AddItem("GROUP 2");
groupNames->AddItem("GROUP 3");
groupNames->SelectItem(0);
CMFCRibbonPanel* pComputerGroups = cComputerGroups->AddPanel("All Groups");
//cComputerGroups is a Category
pComputerGroups->Add(individualComputers);
pComputerGroups->Add(groupNames);
The problem is that , when I select "Group 1" in the groupNames comboBox from the UI(USer Interface) , then even "Computer 1" from the group individualComputers is selected. How do I make each combobox group independent of the other? Thanks.
Solución
I suspect you didn't want add your combobox to itself individualComputers->Add(individualComputers);
should perhaps be pComputerGroups->Add(individualComputers);
Otherwise your bug is probably elsewhere in your command or updateUI handling code not shown. This is likely as you are using the same ID of -1 to identify both combo boxes.
Furthermore there is no overloaded constructor for CMFCRibbonComboBox
which takes an additional two parameters as you have shown for groupNames
.
In the future please show actual code which follows SSCCE
Edit: Made previously unaddressed comment bold as it is likely to be your remaining issue. Consider using const UINT CB_COMP_ID = 1;
and const UINT CB_GROUP_ID = 2;
then you can reference each combo box separately using CB_COMP_ID
or CB_GROUP_ID
in the message map etc.