ListBox delete row without losing position


#1

I’ve got a custom FileListComponent, and I’m trying to delete one of the files without losing the scroll position (as happens on refresh()).

So far I have:

                fileToDelete.deleteFile();
                fileListComponent.updateContent();
                fileListComponent.repaint();

I also tried creating a method to hide a row fileListComponent.hideRow (fileListComponent.getSelectedRow (0));, but no joy.

    void hideRow (int index)
    {
        deselectRow (index);
        getComponentForRowNumber (index)->setSize (getWidth(), 0); 
        getComponentForRowNumber (index)->setVisible (false);
    }

Am I missing something obvious?


#2

The ListBox base class of FileListComponent is marked public so would it not be possible to save the vertical position (ListBox::getVerticalPosition) before removing the row, followed by a call to setVerticalPosition after you’ve removed it.


#3

Thanks @fabian, that worked :slight_smile: