Re: Tree and list view widgets



On Mon, 24 Mar 2003, Fei Wong wrote:

> I'm trying to use the new GtkTreeView and GtkListView widgets. The example
> files that came with the GTK 2.2 library both use the old-style widgets.
> I've followed the sample code in the API documentation, and the end result
> is an empty tree. The documentation doesn't go into great detail on
> inserting items into a tree... This is the first time I've ever read through
> API documentation that said "We'll leave this as an exercise."
>
> Does anyone have any suggestions?

Actually, the section entitled "Creating the model" in the Tree and List
Widget Overview of the GTK+ 2.2 API docs is all you need to solve the
exercise. Of course, to do anything useful, a program will do something
more interesting than hardcoding the tree as in the example provided in
the docs:

  GtkTreeIter iter1;
  GtkTreeIter iter2;

  gtk_tree_store_append (store, &iter1, NULL);
  gtk_tree_store_set (store, &iter1,
		      TITLE_COLUMN, "The Art of Computer Programming",
		      AUTHOR_COLUMN, "Donald E. Knuth",
		      CHECKED_COLUMN, FALSE,
		      -1);
  gtk_tree_store_append (store, &iter2, &iter1);
  gtk_tree_store_set (store, &iter2,
		      TITLE_COLUMN, "Volume 1: Fundamental Algorithms",
		      -1);
  gtk_tree_store_append (store, &iter2, &iter1);
  gtk_tree_store_set (store, &iter2,
		      TITLE_COLUMN, "Volume 2: Seminumerical Algorithms",
		      -1);
  gtk_tree_store_append (store, &iter2, &iter1);
  gtk_tree_store_set (store, &iter2,
		      TITLE_COLUMN, "Volume 3: Sorting and Searching",
		      -1);

But there is not much more to it, IMHO.

I could send a complete example (or you can look for real examples
in /http://cvs.gnome.org/lxr/ident?i=gtk_tree_view_new; There are many more
examples in projects found if http://ftp.gnome.org/pub/gnome/sources)

-- m

-----------------------------------------------------------------------
Mariano Suarez Alvarez
Departamento de Matematica - Universidad Nacional de Rosario
Pellegrini 250 - Rosario 2000 - Argentina

    De la observacion de la irreductibilidad de las creencias ultimas
    he sacado la mayor leccion de mi vida. Aprendi a respetar las ideas
    ajenas, a detenerme ante el secreto de las conciencias, a entender
    antes de discutir, a discutir antes de condenar. Y como estoy en
    vena de confesiones, hago una mas, quizas superflua: detesto con
    toda mi alma a los fanaticos.

    Norberto Bobbio, Italia civil.

-----------------------------------------------------------------------




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