Table List Box - switch two rows

Hi. I’m writing a Soccer Manager Game and I’m using a table list box for displaying team squad. I would like to be able to switch two rows in the table when substituting players but I haven’t figured out how to do so, because I’m completely new to JUCE.
Thanks in advance for any help.

Hi @5H4D0W,
I guess you implemented the ListBoxModel to return the new order of teams. After that you have to call updateContent() on the ListBox to make the change visible.

(I wish, the Listbox was a listener to the ListBoxModel, so that update would be triggered automatically, but unfortunately you have to call that yourself)

I haven’t even figured out how to switch the rows in “nice” way. Whether there exists a possibility to simply for example exchange the indices of the rows in order to swap them. Or whether I need to rewrite values of cells of both rows…

I do manipulations in tableListBoxes all the time - what I do is I manipulate the underlying data and then refresh the table. Works for me.

Thanks a lot. I was just wondering if there exists some easier way. May I have another question?
I’ve got a table class simmilar to the TableListBoxTutorial. And when I in some window need a table I create an instance. In the class of the window I would need to know when the selected row has changed. (Basically I would like to implement the selectedRowsChanged(int last row) method in my window class not inside the table class). Is there an easy way how to do this?

Since ListBoxModel (or TableListBoxModel) is a pure virtual class, you have to inherit it anyway.
So you can add the functionality in the model (which is actually a good design practice).

But you can also simplify by enabling you model taking a lambda instead:

class MyModel : public ListBoxModel
// ...
    void selectedRowsChanged (int lastRowSelected) override
        if (onSelectedRowsChanged != nullptr)
            onSelectedRowsChanged (lastRowSelected);

    std::function<void(int)> onSelectedRowsChanged;
// ...

myModel.onSelectedRowsChanged = [&] (int lastSelectedRow) mutable
    DBG ("lastSelectedRow: " << lastSelectedRow);

Hope that helps

Ok, so how exactly it would be used in my case? I’ve got one header file with the table class and then one cpp file and corresponding header file for the window class, the cpp looks as follows:

        //the constructor    

        //the destructor  

// methods like paint, resized, button clicked...

//There I would need the method that knows that the selected row has been changed