How to remove a row from gtkmm treemodel

I can select a row using this particular code

    Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = imgTreeView->get_selection();

    Gtk::TreeModel::Row rs = imgTreeViewPointer->children()[selectedIndex];

    if (rs)
    {
        refTreeSelection->select(rs);
    }
    Glib::RefPtr<Gtk::TreeModel> tpModel = imgTreeView->get_model();
    Gtk::TreeModel::Children children = tpModel->children();
    Gtk::TreeModel::Children::iterator itn_start,itn_end;

    itn_start = children.begin();
    itn_end = children.end();

    imgTreeView->scroll_to_row(tpModel->get_path(itn_start));
    imgTreeView->scroll_to_row(tpModel->get_path(itn_end));

How can I remove a selected row?

I found this How to remove/erase rows from a selection of a tree view but don’t seem to understand how to use it.

I found this old blog Re: how to remove selected rowS from a ListStore? but don’t seem to understand it as well

I can’t find any example to remove a row here as well, Programming with gtkmm 3

Can anyone help me figure out how to do this?

Found a nice old blog How to remove selected items from a Gtk::TreeView using gtkmm? The painless way.

Gtk::TreeView treeview;
Glib::RefPtr<Gtk::ListStore> store; 
Glib::RefPtr<Gtk::TreeSelection> selection; 

selection = treeview.get_selection(); 
selection->set_mode(Gtk::SELECTION_MULTIPLE); 

void MainWindow::_remove_selected() 
{
vector<Gtk::TreeModel::Path> paths = selection->get_selected_rows();
for(int i = paths.size()-1; i>=0; i--)
store->erase(store->get_iter(paths[i]));
}

Hope it helps someone

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.