Select one of the children in a specific row in treeview


I have added four rows in TreeView and using TreeStore

  • Section A
  • Section B
  • Section C
  • Section D

I am adding a child to Section A based on an event.
using this code

    // Selecting Section A 
    Gtk::TreeModel::Row row = TreeViewPointer->children()[0];
    row = *(TreeViewPointer->append(row.children()));
    row[TreeColumn.col_name] = "Child";

I get the Current result, where the child get added but do not automatically drop down and highlight the child that was recently added

I can iterate through the children of the Section A when new child is added through help of the code in this link.

    type_children children = TreeViewPointer->children();
    for (type_children::iterator iter = children.begin(); iter != children.end(); ++iter)
        Gtk::TreeModel::Row row = *iter;

        Gtk::TreeModel::Row outerRow = TreeViewPointer->children()[0];
        Gtk::TreeModel::Children innerChildren = outerRow.children();
        for (type_children::iterator innerIter = innerChildren.begin(); innerIter != innerChildren.end(); ++innerIter)
            Gtk::TreeModel::Row innerRow = *innerIter;
            Glib::ustring selectedInnerOption = innerRow[TreeColumn.col_name];
            std::cout<<"Item: "<<selectedInnerOption<<std::endl;

        Glib::ustring selectedOuterOption = row[TreeColumn.col_name];
        std::cout<<"Item: "<<selectedOuterOption<<std::endl;


I tried using this code

    typedef Gtk::TreeModel::Children type_children;
    // Select the treeview
    Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = imgTreeView->get_selection();
    // Select the first Row
    Gtk::TreeModel::Row bgRow = treeViewPointer->children()[0];
    // Select the children of the first row
    Gtk::TreeModel::Children innerBgChildren = bgRow.children();
    // Create a iterator for the end/ lastest child in the row
    type_children::iterator lIter = innerBgChildren.end();
    // Select the latest child row
    Gtk::TreeModel::Row latestInnerBgRow = *lIter;
    // Extract the data in the selected latest row
    Glib::ustring slBgRow = latestInnerBgRow[TreeColumn.col_name];
    // Print of data on the terminal
    std::cout<<"Last Item: "<<slBgRow<<std::endl;

    if (bgRow)

    Glib::RefPtr<Gtk::TreeModel> iNtModel = imgTreeView->get_model();
    Gtk::TreeModel::Children children = bgRow.children();

    Gtk::TreeModel::Children::iterator itn_end;

    itn_end = children.end();


I don’t get the Desired result. I can see only Section A getting printed on terminal not Section A child 1

Fully confused could any guide me please

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