Re: TreeModelColumn



Hello,

Chris Vine wrote:
On Saturday 22 October 2005 00:38, Marcelo David wrote:

Hi,

I want to create a dinamic TreeView, then I dont know how many columns I'll
have.

I need another way for get and set values to the columns where I can to
reference a column with an index value (or number of column). In another
words I need to declarate TreeModelColumns to ColumnRecord at runtime and
I'll have an index to referenciate to columns for get and set methods.


You have to know the number of tree model columns (storage data points) when creating the tree model (and the type of each tree model column). In your case the tree model columns could represent the maximum number of columns you might want to display. You connect the Gtk::TreeModel columns to the Gtk::TreeView columns dynamically anyway, with Gtk::TreeView::append_column(), so just don't connect up the tree model columns you don't want displayed (they will then be hidden).

I managed to create TreeView without knowing the type of each columns (nor the number of columns) at compile time, but I have had problems if I use

int Gtk::TreeView::append_column(const Glib::ustring& title,const TreeModelColumn<ColumnType>& model_column)

instead of

int Gtk::TreeView::append_column (const Glib::ustring& title, CellRenderer& cell) .

The problem is that in the first case the rows are there (i could select them with the mouse), but the content is not visible, i.e. the cells are all empty :-) Using the second method it work nicely. I think I am missing to call something that the second method is in fact calling. Maybe if I show the code someone could try to help me out:

  m_refTreeModel = Gtk::ListStore::create(m_Columns);
  m_TreeView.set_model(m_refTreeModel);

  //Fill the TreeView's model
  Gtk::TreeModel::Row row = *(m_refTreeModel->append());
  row.set_value (0, (guint)10);
................

Gtk::TreeViewColumn* lTVC = new Gtk::TreeViewColumn ("Name", *new Gtk::CellRendererText ());
  m_TreeView.append_column (*lTVC);

Thanks in advance,
Luca



Tree models are just structured data points, which you can display with a tree view. You don't in fact have to display any or all of the tree model columns if you choose not to do so. If you think of them that way then it should be reasonably straightforward.

Incidentally you can sort on a hidden tree model column - that is quite a common use of them.

Chris

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]