How to get access to button in refreshComponentForCell

Does anyone know how to target / access a child button created in a table list box using refreshComponentForCell? I need to change the toggle state of the button in the table when something happens in the app. I’ve tried things like getting the component via row and col using getCellComponent(row, col). This returns the correct enclosing component I can show and hide, but I have no idea how to get inside that to access the toggle button and its state that is created in there. I even tried building a vector and putting all the buttons in there, but this does not work either. This is probably a dumb question, but I’m a noob, any advice really appreciated, I’m really stumped on this one.

juce::Component* Playlist::refreshComponentForCell(int rowNumber, int columnId, bool /*isRowSelected*/,
    juce::Component* existingComponentToUpdate)

    if (columnId == 4)

        if (existingComponentToUpdate == nullptr)
            juce::ToggleButton* btn = new juce::ToggleButton;
            btn->onClick = {  doStuff(); };
            existingComponentToUpdate = btn;


    return existingComponentToUpdate;


Trying to access it like this (does not work):

void Playlist::DragComplete()

// trying to do something like this...
// table.getCellComponent(4,1)->btn.getToggleState();

// this correctly hides the button, but I need to change the toggle state 
table.getCellComponent(4, 1)->setVisible(false);


You could dynamic_cast the result of getCellComponent to a Button:

if (auto* button = dynamic_cast <Button*> (table.getCellComponent(4, 1))
1 Like

Thanks for your help, much appreciated. I ended up figuring out what I needed. The vectors did actually work after more experimentation. Since these are groups of radio buttons I ended up making two vectors of each set of toggles which allows me to more easily manage them since other events turn them on / off. I would have liked to use the radio group functionality like in the tutorials but it doesn’t work since the buttons all inside their own component because of the refreshComponentForCell.

Making the vectors works like so:


and then declare the vector like:

    std::vector<juce::ToggleButton*> toggles1;