TreeView change cell data

Hello everyone,

I am trying to change the value of a cell value which is defined as ;

Glib::RefPtr<Gtk::ListStore> m_refTreeModel;

and accessed from ;

  auto row1 = *(m_refTreeModel->append());
  row1[m_Columns.m_col_id] = 1;
  row1[m_Columns.m_col_name] = "Billy Bob";
  row1[m_Columns.m_col_number] = 10;
  row1[m_Columns.m_col_percentage] = 15;

I would like to change the value of m_Columns.m_col_percentage value upon an event such as a function call. First definition I wrote is in the header and cell fillings are in the main source code. I would like to learn how to access and set row1[m_Columns.m_col_percentage] value from an external function. I am on gtk4mm

Hello @kaile!

If you know the index of the row you have to modify, you can simply write:

m_refTreeModel.children()[row_index][m_Columns.m_col_percentage] = value;

If the row order may change and you don’t want to keep track of it, then create a Gtk::TreeReference when creating the row initially.

I know the index of the row that I can input. But m_refTreeModel = Gtk::ListStore::create(m_Columns); does not have a children() member thus I can’t access it. On the other hand why I am not able to access row1 from an external function ? Currently I am studying on ;

The value changed when I addressed the member ; m_refTreeModel->children()[0][m_Columns.m_col_percentage] = 100;. Do you think there is something wrong with my setup ? :slightly_smiling_face:

Ah indeed, the arrow operator (->) is needed here :slightly_smiling_face:

1 Like

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