Using a treeview with a dynamic number of columns
- From: "Thiago Guzella" <thiago guzella gmail com>
- To: gtkmm-list gnome org
- Subject: Using a treeview with a dynamic number of columns
- Date: Wed, 1 Mar 2006 23:51:54 -0300
Greetings everyone,
I am writing a Gtkmm app that contains a treeview, composed of a given
number of columns that are always visible, followed by columns that
are dynamically handled. Depending on user actions, a "dynamic" column
in the treeview needs to be added or removed. I have been implementing
this pattern in the following way:
class TreeViewColumns : public Gtk::TreeModel::ColumnRecord {
Gtk::TreeModelColumn<Glib::ustring> constant_column_1;
Gtk::TreeModelColumn<Glib::ustring> constant_column_2;
Gtk::TreeModelColumn<Glib::ustring> constant_column_3;
vector< Gtk::TreeModelColumn<Glib::ustring> > dynamic_columns;
...
TreeViewColumns() {
// Add the constant columns
add(constant_column_1);
add(constant_column_1);
add(constant_column_1);
}
void addDynamicColumn() {
// Insert the column
dynamic_columns.push_back(Gtk::TreeModelColumn<Glib::ustring> ());
// Add the new, dynamic, column
add(dynamic_columns.back());
}
};
class MyTreeView : public Gtk::TreeView {
TreeViewColumns m_cols;
Glib::RefPtr<Gtk::ListStore> m_ref_tree_model;
MyTreeView() /* m_cols initialized; constant columns added */ {
// Create list store
m_ref_tree_model = Gtk::ListStore::create(*m_cols);
// Set the tree model
set_model(m_ref_tree_model);
}
};
But, after experimenting, I have come to the conclusion that I can't
just add a column (by calling TreeViewColumns::addDynamicColumn) and
using MyTreeView::append_column.
After reading a previous thread
(http://mail.gnome.org/archives/gtkmm-list/2002-July/msg00367.html), I
tried to, when adding a new column, clear the columns, add the dynamic
column, running Gtk::TreeModel::ColumnRecord::add for each column to
be displayed, recreating the list store and updating the tree model.
But that doesn't seem to work. So, I would like to ask, how should
this scheme be implemented?
--
Thiago dos Santos Guzella
Electrical Enginnering Student - UFMG (www.ufmg.br), Brazil
Linux User #354160
UIN: 13465286. Jabber: tguzella At jabber Dot org
"Faith: not wanting to know what is true."
Friedrich Nietzsche
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]