[Mono-docs-list] can we include this in the Gnome.NET Tutorial?

Miguel de Icaza miguel@ximian.com
04 Mar 2003 16:21:23 -0500


--=-atbUxa4AJemN0CniTZQz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit



--=-atbUxa4AJemN0CniTZQz
Content-Disposition: inline
Content-Description: Forwarded message - Re: [Gtk-sharp-list] Using
	ListViews/TreeViews in Gtk#?
Content-Type: message/rfc822

Return-Path: <gtk-sharp-list-admin@lists.ximian.com>
Delivered-To: miguel@peabody.ximian.com
Received: (qmail 28702 invoked from network); 4 Mar 2003 16:35:33 -0000
Received: from skeptopotamus.ximian.com (141.154.95.14) by
	peabody.ximian.com with SMTP; 4 Mar 2003 16:35:33 -0000
Received: by skeptopotamus.ximian.com (Postfix) id 0BD2D630AB; Tue,  4 Mar
	2003 11:35:33 -0500 (EST)
Delivered-To: miguel@ximian.com
Received: from listsmx.ximian.com (headcheese.ximian.com [141.154.95.15])
	by skeptopotamus.ximian.com (Postfix) with ESMTP id ECA60630A0; Tue,  4 Mar
	2003 11:35:32 -0500 (EST)
Received: from headcheese.ximian.com (localhost [127.0.0.1]) by
	listsmx.ximian.com (Postfix) with ESMTP id 8F75D1249F1; Tue,  4 Mar 2003
	11:02:02 -0500 (EST)
Received: from falcon.cc.mala.bc.ca (falcon.cc.mala.bc.ca [142.231.39.34])
	by listsmx.ximian.com (Postfix) with ESMTP id F07A7124851 for
	<gtk-sharp-list@lists.ximian.com>; Tue,  4 Mar 2003 11:01:47 -0500 (EST)
Received: from falcon.cc.mala.bc.ca (localhost.localdomain [127.0.0.1]) by
	falcon.cc.mala.bc.ca (8.12.7/8.12.7) with ESMTP id h24FxeYo002427 for
	<gtk-sharp-list@lists.ximian.com>; Tue, 4 Mar 2003 07:59:40 -0800
Received: (from george@localhost) by falcon.cc.mala.bc.ca
	(8.12.7/8.12.7/Submit) id h24Fxeic002425 for
	gtk-sharp-list@lists.ximian.com; Tue, 4 Mar 2003 07:59:40 -0800
X-Authentication-Warning: falcon.cc.mala.bc.ca: george set sender to
	farrisg@mala.bc.ca using -f
Subject: Re: [Gtk-sharp-list] Using ListViews/TreeViews in Gtk#?
From: George Farris <farrisg@mala.bc.ca>
To: Gtk Sharp List <gtk-sharp-list@lists.ximian.com>
In-Reply-To: <1046792388.13594.13.camel@localhost.localdomain>
References: <1046784580.1252.7.camel@localhost.localdomain>
	 <1046791996.1059.2.camel@jorge.linuxware.net>
	 <1046792388.13594.13.camel@localhost.localdomain>
X-Security: MIME headers sanitized on peabody See
	http://www.impsec.org/email-tools/sanitizer-intro.html for details.
	$Revision: 1.132 $Date: 2001-12-05 20:20:17-08 
Content-Type: multipart/mixed; boundary="=-V4hV66EM/E5hAWk2Q5aU"
Organization: 
Message-Id: <1046793580.2317.8.camel@falcon.cc.mala.bc.ca>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.2.1 (1.2.1-4) 
Sender: gtk-sharp-list-admin@lists.ximian.com
Errors-To: gtk-sharp-list-admin@lists.ximian.com
X-BeenThere: gtk-sharp-list@lists.ximian.com
X-Mailman-Version: 2.0.13
Precedence: bulk
List-Help: <mailto:gtk-sharp-list-request@lists.ximian.com?subject=help>
List-Post: <mailto:gtk-sharp-list@lists.ximian.com>
List-Subscribe: <http://lists.ximian.com/mailman/listinfo/gtk-sharp-list>,
	<mailto:gtk-sharp-list-request@lists.ximian.com?subject=subscribe>
List-Id: Discussion of the C# bindings for Gtk+
	<gtk-sharp-list.lists.ximian.com>
List-Unsubscribe:
	<http://lists.ximian.com/mailman/listinfo/gtk-sharp-list>,
	<mailto:gtk-sharp-list-request@lists.ximian.com?subject=unsubscribe>
List-Archive: <http://lists.ximian.com/archives/public/gtk-sharp-list/>
Date: 04 Mar 2003 07:59:40 -0800
X-Spam-Status: No, hits=-2.1 required=5.0
	tests=IN_REP_TO,KNOWN_MAILING_LIST,QUOTED_EMAIL_TEXT,REFERENCES,
	SPAM_PHRASE_01_02,SUBJECT_IS_LIST,X_AUTH_WARNING version=2.43
X-Spam-Level: 


--=-V4hV66EM/E5hAWk2Q5aU
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I did some preliminary docs for TreeView with a ListStore model and sent
them to the mono-doc mail list, have heard a peep????  I'll included it
here for you.  I haven't written the selection information yet though I
do have examples.


On Tue, 2003-03-04 at 07:39, Charles-Louis wrote:
> Le mar 04/03/2003 =E0 16:33, Jorge De Gante a =E9crit :
> > Hi Charles
> >=20
> >=20
> > Check the sample that comes with gtk-sharp, the file is TreeViewDemo.cs
> > or the source of the doc browser browser.cs, both samples are about
> > treeviews.
>=20
> I already looked at the TreeViewDemo.cs (it seems I don't have the doc
> browser? which package should I download?), but it's using an iterator
> to populate the treeview with an XML file.
>=20
> I'm writing a LogViewer, and I have to be able to add items line per
> line (eg. when clicking on a Button)
>=20
> Aren't there any methods like TreeView.Add(item)?
>=20
>=20
> >=20
> > El mar, 04-03-2003 a las 07:29, Charles-Louis escribi=F3:
> > > Hello,
> > >=20
> > > I'm pretty new to programming with Gtk and Glade. I've designed an
> > > application with Glade that should use ListViews (but I found out tha=
t
> > > ListViews were deprecated... so I've used a TreeView instead).
> > >=20
> > > I wanted to know how I can populate these Views=20
> > >=20
> > > eg. ---------------------------------------
> > >     |First Name   |Last Name    | Info    |
> > >     ---------------------------------------
> > >     |Chuck        |Berry        | Artist  |
> > >     ---------------------------------------
> > >     |John         |Johnson      | Baker   |
> > >     ---------------------------------------
> > >=20
> > >=20
> > > Regards
> > > --=20
> > > Charles-Louis <charlouis.mono@wanadoo.be>
> > >=20
> > > _______________________________________________
> > > Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> > > http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
--=20

--=-V4hV66EM/E5hAWk2Q5aU
Content-Disposition: attachment; filename="treeview.html"
Content-Type: text/html; name="treeview.html"; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV=3D"CONTENT-TYPE" CONTENT=3D"text/html; charset=3Dutf-8">
	<TITLE>The Mono Handbook - GNOME.NET - GTK#</TITLE>
</HEAD>
<BODY LANG=3D"en-US">
<P><BR>
</P>
<H1>GTK#</H1>
<H2>Miscellaneous Widgets</H2>
<H3>Tree and List Widget</H3>
<P>The TreeView widget is one of the more complex GTK widgets. It is
well worth while spending some time studing it carefully.=20
</P>
<P>These widgets are designed around a <I>Model/View/Controller</I>
design and consists of four major parts:</P>
<P><B>GtkTreeView :</B> the tree view widget</P>
<P><B>GtkTreeViewColumn</B> : the view column</P>
<P><B>GtkCellRenderer</B> : the cell renderers</P>
<P><B>GtkTreeModel</B> : the model interface</P>
<P>A quick look at the situation boils down to this:</P>
<P>CellRender -----&gt; TreeViewColumn -----&gt; TreeView</P>
<P>A cell (CellRenderer) of type =E2=80=9Ctext=E2=80=9D, =E2=80=9Cpixbuf=E2=
=80=9D or =E2=80=9Ctoggle=E2=80=9D
is created and packed into a newly created column (TreeViewColumn).
The column in turn is appended to the tree (TreeView). Data is added
to the tree model (TreeStore or ListStore) and the model is
associated with the newly created tree.</P>
<P><BR><BR>
</P>
<P>Lets start with a simple example and explain as we go:</P>
<P>We'll create a simple list view with one column and text data
stored in it. We could of course create multiple columns of different
types but for our purposes, simple is better.</P>
<P>Lets create the TreeView widget first. We'll assume that the
parent widget that we are going to pack the TreeView widget into has
already been created.</P>
<P>First we create a ListStore for holding the data that our list
widget is going to display.</P>
<P>The ListStore object is a list model for use with a TreeView
widget. It implements the TreeModel interface, and consequentialy,
can use all of the methods available there. It also implements the
TreeSortable interface so it can be sorted by the view. Finally, it
also implements the tree interfaces.</P>
<PRE STYLE=3D"margin-bottom: 0.5cm">ListStore store =3D null;</PRE><P>
Next we create a new TreeView widget and associate our newly created
ListStore with the TreeView.</P>
<PRE STYLE=3D"margin-bottom: 0.5cm">TreeView tv =3D new TreeView (store);</=
PRE><P>
Here we assign attributes to the TreeView such as making sure headers
are on. Headers refer to the column headers that appear as buttons
and may be tied to such functions as sorting the view of column data.</P>
<PRE STYLE=3D"margin-bottom: 0.5cm">tv.HeadersVisible =3D true;</PRE><P>
Now we need to add columns to our TreeView. We are going to add one
column. We get a new TreeViewColumn and a new CellRenderer of type
=E2=80=9Ctext=E2=80=9D to add to our column.=20
</P>
<P><BR><BR>
</P>
<PRE>TreeViewColumn NameCol =3D new TreeViewColumn ();
CellRenderer NameRenderer =3D new CellRendererText ();
NameCol.Title =3D &quot;Name&quot;;
NameCol.PackStart (NameRenderer, true);
NameCol.AddAttribute (NameRenderer, &quot;text&quot;, 0);
tv.AppendColumn (NameCol);</PRE><P>
Since we aren't going to add any more columns to our TreeView we can
finish by packing it into whatever parent widget we have.=20
</P>
<PRE>mywidget.Add (tv);</PRE><P>
mywidget.ShowAll ();</P>
<P><BR><BR>
</P>
<P>Our next task is to to populate the TreeView with data. Data is
stored in the ListStore that was created as the first step above.
When a ListStore or TreeStore is created we tell it what type of data
the store is holding for each column . In the example below we have
one column of type =E2=80=9Cstring=E2=80=9D.=20
</P>
<P>store =3D new ListStore ((int)TypeFundamentals.TypeString);</P>
<P>If we had more than one column we would expand the creation of the
ListStore to include those columns and their type. Here is an example
that creates two columns, one of type =E2=80=9Cbool=E2=80=9D and one of typ=
e
=E2=80=9Cstring=E2=80=9D.</P>
<PRE>store =3D new ListStore ((int)TypeFundamentals.TypeBool,(int)TypeFunda=
mentals.TypeString);

Right now lets put some data in our list.  We need to get a new TreeIter.  =
A TreeIter is used=20
to store the location where the data will be stored.  The TreeIter is updat=
ed automatically=20
here bye a call to store.Append, we don't actually set the TreeIter.  We ne=
ed to=20
append a TreeIter to the store to before we can store data in it.

<PRE>TreeIter iter =3D new TreeIter ();</PRE>

Great now lets put four rows of text data into the list.  The ListStore and=
 TreeStore actually=20
store a Glib.Value not a text string so first we must store our string in a=
 Glib.Value then=20
we can set the value in the ListStore.  Note the =E2=80=9C0=E2=80=9D in the=
 SetValue call is acually the=20
column we are writing data to.
<PRE>
for (int i =3D 0; i &lt; 4; i++) {
  GLib.Value value =3D new Glib.Value(=E2=80=9Cdata =E2=80=9D+i.ToString())=
;
  store.Append (out iter);
  store.SetValue (iter, 0, value);
}
</PRE>
<H2>Example</H2>
<P>Here is a complete example of what we have just done above
complete with toplevel window.</P>
<PRE>namespace Samples {
        using System;
        using System.Drawing;
        using GLib;
        using Gtk;
        using GtkSharp;


        public class TreeView {
               =20
                public static void Main (string[] args)
                {
                        TreeStore store =3D null;
                                               =20
                        Application.Init ();


                        store =3D new TreeStore ((int)TypeFundamentals.Type=
String,
                                               (int)TypeFundamentals.TypeSt=
ring);


                        TreeIter iter =3D new TreeIter ();
                       =20
                        for (int i=3D0; i&lt;10; i++)
                        {
                                GLib.Value Name =3D new GLib.Value (&quot;D=
emo &quot; +
i.ToString());
                                GLib.Value Type =3D new GLib.Value (&quot;D=
ata &quot; +
i.ToString());
                                store.Append (out iter);
                                store.SetValue (iter, 0, Name);
                                store.SetValue (iter, 1, Type);
                        }
                       =20
                        Window win =3D new Window (&quot;TreeView List Demo=
&quot;);
                        win.DeleteEvent +=3D new DeleteEventHandler (delete=
_cb);
                        win.DefaultSize =3D new Size (400,250);


                        ScrolledWindow sw =3D new ScrolledWindow ();
                        win.Add (sw);


                        TreeView tv =3D new TreeView (store);
                        tv.HeadersVisible =3D true;


                        TreeViewColumn DemoCol =3D new TreeViewColumn ();
                        CellRenderer DemoRenderer =3D new CellRendererText =
();
                        DemoCol.Title =3D &quot;Demo&quot;;
                        DemoCol.PackStart (DemoRenderer, true);
                        DemoCol.AddAttribute (DemoRenderer, &quot;text&quot=
;, 0);
                        tv.AppendColumn (DemoCol);


                        TreeViewColumn DataCol =3D new TreeViewColumn ();
                        CellRenderer DataRenderer =3D new CellRendererText =
();
                        DataCol.Title =3D &quot;Data&quot;;
                        DataCol.PackStart (DataRenderer, false);
                        DataCol.AddAttribute (DataRenderer, &quot;text&quot=
;, 1);
                        tv.AppendColumn (DataCol);


                        sw.Add (tv);
                        sw.Show();
                        win.ShowAll ();
                        Application.Run ();
                }


                private static void delete_cb (System.Object o, DeleteEvent=
Args
args)
                {
                        Application.Quit ();
                        args.RetVal =3D true;
                }
        }
}</PRE>
</BODY>
</HTML>

--=-V4hV66EM/E5hAWk2Q5aU--
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list


--=-atbUxa4AJemN0CniTZQz--