# RadioGroupId doesn't work between different components

**URL:** <https://forum.juce.com/t/radiogroupid-doesnt-work-between-different-components/31703>\
**Category:** General JUCE discussion\
**Created:** [February 10, 2019, 4:16pm UTC](https://forum.juce.com/t/radiogroupid-doesnt-work-between-different-components/31703 "2019-02-10T16:16:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [February 10, 2019, 4:16pm UTC](https://forum.juce.com/t/radiogroupid-doesnt-work-between-different-components/31703/1 "2019-02-10T16:16:15Z")

</div>

According to me RadioButtons doesn’t work between RadioButtons objects instantiated in different components objects.

Following tutorial “Radio Buttons and Checkerboxes”, I created on my MainComponent 2 RadioButtons and I gave them the same RadioGroupId, after I tried to create another Component class (creating .cpp file and .h file in Projucer) where I instantiated other RadioButtons and also to them I gave the same RadioGroupId owned by my two objects in Main Component. When I build the app however it works only between objects contained in the same component, so if in MainComponent I select the first RadioButton, the second one turn off, but when I turn on any RadioButton contained on the other component class the RadioButtons of the MainComponent Class remains selected.

It’s right or there’s a way to select only one RadioButton also between different component classes?

Thank you in advice!

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [February 10, 2019, 4:33pm UTC](https://forum.juce.com/t/radiogroupid-doesnt-work-between-different-components/31703/2 "2019-02-10T16:33:54Z")

</div>

The docs for `setRadioGroupId` say:

> To find other buttons with the same ID, this button will search through its sibling components for ToggleButtons, so all the buttons for a particular group must be placed inside the same parent component.

If you want to spread the same radio group across different components, you’ll need to find some other solution. Perhaps something like this:

- Use a `juce::Value` to store some information about the selected button (its name or some other unique id)
- When a button is pressed, update the value with the id of the selected button
- When the `Value` changes (use the `Listener` system to receive change notifications), compare the value to the id of each button, and only leave a button selected if its id matches the value.

---

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [February 10, 2019, 4:55pm UTC](https://forum.juce.com/t/radiogroupid-doesnt-work-between-different-components/31703/3 "2019-02-10T16:55:00Z")

</div>

Thank you reuk! I’ll try this way!
