[Mono-docs-list] monkeyguide treeview.html update
John Luke
jluke@cfl.rr.com
12 Jul 2003 20:57:46 -0400
--=-sLJykRfokRlVRnyBymsv
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hello,
Here is an update for
monkeyguide/html/en/gnome/bindings/gtk-sharp/treeview.html to use the
new easy way.
John
--=-sLJykRfokRlVRnyBymsv
Content-Disposition: attachment; filename=treeview.html.diff
Content-Type: text/x-patch; name=treeview.html.diff; charset=UTF-8
Content-Transfer-Encoding: 7bit
Index: treeview.html
===================================================================
RCS file: /cvs/public/monkeyguide/html/en/gnome/bindings/gtk-sharp/treeview.html,v
retrieving revision 1.6
diff -u -r1.6 treeview.html
--- treeview.html 26 Jun 2003 21:17:38 -0000 1.6
+++ treeview.html 13 Jul 2003 00:56:43 -0000
@@ -39,19 +39,19 @@
<p>Lets create the <i>TreeView</i> widget first. We'll assume that
the parent widget that we are going to pack the <i>TreeView</i>
widget into has already been created.</p>
-<p>First we create a <i>ListStore</i> for holding the data that our
+<p>First we create a <i>TreeStore</i> for holding the data that our
list widget is going to display.</p>
-<p>The <i>ListStore</i> object is a list model for use with a
+<p>The <i>TreeStore</i> object is a model for use with a
<i>TreeView</i> widget. It implements the <i>TreeModel</i>
interface, and consequentialy, can use all of the methods available
there. It also implements the <i>TreeSortable</i> interface so it
can be sorted by the view. Finally, it also implements the tree
interface.</p>
<pre class="code">
-ListStore store = null;
+TreeStore store = null;
</pre>
<p>Now we create a new <i>TreeView</i> widget and associate our
-newly created <i>ListStore</i> with the <i>TreeView</i>.</p>
+newly created <i>TreeStore</i> with the <i>TreeView</i>.</p>
<pre class="code">
TreeView tv = new TreeView (store);
</pre>
@@ -78,12 +78,7 @@
<i>AddAttribute</i> can be used to set such things as column
colours.</p>
<pre class="code">
-TreeViewColumn NameCol = new TreeViewColumn ();
-CellRenderer NameRenderer = new CellRendererText ();
-NameCol.Title = "Name";
-NameCol.PackStart (NameRenderer, true);
-NameCol.AddAttribute (NameRenderer, "text", 0);
-tv.AppendColumn (NameCol);
+tv.AppendColumn ("Demo", new CellRendererText (), "text", 0);
</pre>
<p>Since we aren't going to add any more columns to our
<i>TreeView</i> we can finish by packing it into whatever parent
@@ -93,41 +88,25 @@
mywidget.ShowAll ();
</pre>
<p>Our next task is to to populate the <i>TreeStore</i> with data.
-Data is stored in the <i>ListStore</i> that was created as the
+Data is stored in the <i>TreeStore</i> that was created as the
first step above. When a <i>ListStore</i> or <i>TreeStore</i> 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
string.</p>
<pre class="code">
-store = new ListStore ((int)TypeFundamentals.TypeString);
+store = new TreeStore (typeof (string));
</pre>
<p>If we had more than one column we would expand the creation of
-the <i>ListStore</i> to include those columns and their type. Here
+the <i>TreeStore</i> to include those columns and their type. Here
is an example that creates two columns, one of type <b>boolean</b>
and one of type <b>string</b>.</p>
<pre class="code">
-store = new ListStore ((int)TypeFundamentals.TypeBoolean,(int)TypeFundamentals.TypeString);
+store = new TreeStore (typeof (Boolean), typeof (string));
</pre>
-Right now lets put some data in our list. We need to get a new
-<i>TreeIter</i>. A <i>TreeIter</i> is used to store the location
-where the data will be stored. The <i>TreeIter</i> is updated
-automatically here bye a call to <i>store.Append</i>, we don't
-actually set the <i>TreeIter</i>. We will need to append the
-<i>TreeIter</i> to the "store" to before we can place data in it.
-<pre class="code">
-TreeIter iter = new TreeIter ();
-</pre>
-Great now lets put four rows of text data into the list. The
-<i>ListStore</i> and <i>TreeStore</i> actually store a
-<i>Glib.Value</i> not a text string so first we must store our
-string in a <i>Glib.Value</i> then we can set the value in the
-<i>ListStore</i>. Note the <b>0</b> in the <i>SetValue</i> call is
-actually the column we are writing data to.
-<pre class="code">
-for (int i = 0; i < 4; i++) {
- GLib.Value value = new Glib.Value(data +i.ToString());
- store.Append (out iter);
- store.SetValue (iter, 0, value);
+Great now lets put five rows of text data into the list.
+<pre class="code">
+for (int i = 0; i < 5; i++) {
+ TreeIter iter = store.AppendValues ("Demo " + i, "Data " + i);
}
</pre>
<h2>Example</h2>
@@ -135,79 +114,49 @@
toplevel window.</p>
<pre class="code">
namespace Samples {
- using System;
- using System.Drawing;
- using GLib;
- using Gtk;
- using GtkSharp;
-
+ using System;
+ using Gtk;
+ using GtkSharp;
- public class TreeView {
+ public class TreeViewSample {
- public static void Main (string[] args)
- {
- TreeStore store = null;
-
- Application.Init ();
-
-
- store = new TreeStore ((int)TypeFundamentals.TypeString,
- (int)TypeFundamentals.TypeString);
-
-
- TreeIter iter = new TreeIter ();
-
- for (int i=0; i<10; i++)
- {
- GLib.Value Name = new GLib.Value ("Demo " + i.ToString());
- GLib.Value Type = new GLib.Value ("Data " + i.ToString());
- store.Append (out iter);
- store.SetValue (iter, 0, Name);
- store.SetValue (iter, 1, Type);
- }
+ public static void Main (string [] args)
+ {
+ Application.Init ();
+
+ TreeStore store = new TreeStore (typeof (string), typeof (string));
+
+ for (int i=0; i < 5; i++)
+ {
+ TreeIter iter = store.AppendValues ("Demo " + i, "Data " + i);
+ }
- Window win = new Window ("TreeView List Demo");
- win.DeleteEvent += new DeleteEventHandler (delete_cb);
- win.DefaultSize = new Size (400,250);
-
-
- ScrolledWindow sw = new ScrolledWindow ();
- win.Add (sw);
-
+ Window win = new Window ("TreeView List Demo");
+ win.DeleteEvent += new DeleteEventHandler (delete_cb);
+ win.SetDefaultSize (400,250);
+
+ ScrolledWindow sw = new ScrolledWindow ();
+ win.Add (sw);
+
+ TreeView tv = new TreeView ();
+ tv.Model = store;
+ tv.HeadersVisible = true;
- TreeView tv = new TreeView (store);
- tv.HeadersVisible = true;
-
-
- TreeViewColumn DemoCol = new TreeViewColumn ();
- CellRenderer DemoRenderer = new CellRendererText ();
- DemoCol.Title = "Demo";
- DemoCol.PackStart (DemoRenderer, true);
- DemoCol.AddAttribute (DemoRenderer, "text", 0);
- tv.AppendColumn (DemoCol);
-
-
- TreeViewColumn DataCol = new TreeViewColumn ();
- CellRenderer DataRenderer = new CellRendererText ();
- DataCol.Title = "Data";
- DataCol.PackStart (DataRenderer, false);
- DataCol.AddAttribute (DataRenderer, "text", 1);
- tv.AppendColumn (DataCol);
-
-
- sw.Add (tv);
- sw.Show();
- win.ShowAll ();
- Application.Run ();
- }
-
-
- private static void delete_cb (System.Object o, DeleteEventArgs args)
- {
- Application.Quit ();
- args.RetVal = true;
- }
- }
+ tv.AppendColumn ("Demo", new CellRendererText (), "text", 0);
+ tv.AppendColumn ("Data", new CellRendererText (), "text", 1);
+
+ sw.Add (tv);
+ sw.Show ();
+ win.ShowAll ();
+ Application.Run ();
+ }
+
+ private static void delete_cb (System.Object o, DeleteEventArgs args)
+ {
+ Application.Quit ();
+ args.RetVal = true;
+ }
+ }
}
</pre>
<div class="copyright">The Mono Handbook |
--=-sLJykRfokRlVRnyBymsv--