mail-archives/gtk-sharp-list/2005-August/006339.html

273 строки
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] Problems with TreeView
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Problems%20with%20TreeView&In-Reply-To=1124130909.13130.10.camel%40localhost.localdomain">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="006327.html">
<LINK REL="Next" HREF="006340.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] Problems with TreeView</H1>
<B>Todd Berman</B>
<A HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Problems%20with%20TreeView&In-Reply-To=1124130909.13130.10.camel%40localhost.localdomain"
TITLE="[Gtk-sharp-list] Problems with TreeView">tberman at off.net
</A><BR>
<I>Mon Aug 15 16:50:47 EDT 2005</I>
<P><UL>
<LI>Previous message: <A HREF="006327.html">[Gtk-sharp-list] Problems with TreeView
</A></li>
<LI>Next message: <A HREF="006340.html">[Gtk-sharp-list] Problems with TreeView
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#6339">[ date ]</a>
<a href="thread.html#6339">[ thread ]</a>
<a href="subject.html#6339">[ subject ]</a>
<a href="author.html#6339">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>I think you need to get a Beginning C# type book.
You need to make ListStore static as you are aware.
However, here is why you get that nullreference crash:
ListStore store = new ListStore (typeof (string), typeof
(string));
That code right there creates a local (to the method) ListStore.
You want:
store = new ListStore (typeof (string), typeof (string));
That will cause the static ListStore store to be assigned properly.
--Todd
On Mon, 2005-08-15 at 20:35 +0200, Andr&#233; Kuntze wrote:
&gt;<i> Hi everybody,
</I>&gt;<i>
</I>&gt;<i> i am trying to do the following in mono using c# and gtk#: Having a
</I>&gt;<i> simple two column list with word and numbers. When you edit one field in
</I>&gt;<i> any column, write the new text into the edited field.
</I>&gt;<i>
</I>&gt;<i> This must sound so newbish but i am struggeling with this a few hours
</I>&gt;<i> now and so i decided to ask some people in the know. Til now i got this:
</I>&gt;<i>
</I>&gt;<i> ** SNIP: CODE STARTS HERE
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> /*
</I>&gt;<i> * Filename: TreeViewTryOut.cs
</I>&gt;<i> * Date: 15.08.2005
</I>&gt;<i> *
</I>&gt;<i> * Description: This program is a TryOut for the editable
</I>&gt;<i> * TreeView - widget.
</I>&gt;<i> * The rows in the TreeView are editable and should
</I>&gt;<i> * take the new value, when entered.
</I>&gt;<i> */
</I>&gt;<i>
</I>&gt;<i> using System;
</I>&gt;<i> using Gtk;
</I>&gt;<i>
</I>&gt;<i> class MainClass{
</I>&gt;<i>
</I>&gt;<i> // Make the variable store visible to the whole class to use it
</I>&gt;<i> // in the code for the Edited event
</I>&gt;<i> ListStore store;
</I>&gt;<i>
</I>&gt;<i> public static void Main(string [] args){
</I>&gt;<i> Application.Init();
</I>&gt;<i>
</I>&gt;<i> // Definition of my window, which contains the editable
</I>&gt;<i> // Two - Column - List
</I>&gt;<i> Window window = new Window (&quot;TreeView&quot;);
</I>&gt;<i> window.DeleteEvent += Window_Deleted;
</I>&gt;<i>
</I>&gt;<i> VBox vertBox = new VBox();
</I>&gt;<i> vertBox.BorderWidth = 6;
</I>&gt;<i>
</I>&gt;<i> window.Add(vertBox);
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> // Definition of my TreeView
</I>&gt;<i> TreeView treeView = new TreeView();
</I>&gt;<i> treeView.HeadersVisible = true;
</I>&gt;<i>
</I>&gt;<i> vertBox.Add(treeView);
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> // Definition of the colums
</I>&gt;<i> TreeViewColumn column = new TreeViewColumn();
</I>&gt;<i> column.Title = &quot;Word&quot;;
</I>&gt;<i> CellRendererText colText = new CellRendererText();
</I>&gt;<i>
</I>&gt;<i> // Here i add the editable flag and the Edited event
</I>&gt;<i> colText.Editable = true;
</I>&gt;<i> colText.Edited += Word_Edited;
</I>&gt;<i> column.PackStart (colText, true);
</I>&gt;<i> column.AddAttribute (colText, &quot;text&quot;, 0);
</I>&gt;<i> treeView.AppendColumn (column);
</I>&gt;<i>
</I>&gt;<i> column = new TreeViewColumn();
</I>&gt;<i> column.Title = &quot;Page&quot;;
</I>&gt;<i> colText = new CellRendererText();
</I>&gt;<i>
</I>&gt;<i> // Here i add the editable flag and the Edited event
</I>&gt;<i> colText.Editable = true;
</I>&gt;<i> colText.Edited += Word_Edited;
</I>&gt;<i> column.PackStart (colText, true);
</I>&gt;<i> column.AddAttribute (colText, &quot;text&quot;, 1);
</I>&gt;<i> treeView.AppendColumn (column);
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> // Definition of the field types
</I>&gt;<i> ListStore store = new ListStore (typeof (string), typeof
</I>&gt;<i> (string));
</I>&gt;<i> treeView.Model = store;
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> // Putting stuff in the list
</I>&gt;<i> TreeIter iterator = new TreeIter();
</I>&gt;<i> iterator = store.AppendValues(&quot;ChangeMe&quot;, &quot;1&quot;);
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> // Show the not working stuff :-/
</I>&gt;<i> window.ShowAll();
</I>&gt;<i> Application.Run();
</I>&gt;<i> }
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> // My not working code, when a field is edited
</I>&gt;<i> static void Word_Edited (object o, EditedArgs e){
</I>&gt;<i> // When edited get me the current field
</I>&gt;<i> TreeIter iterator;
</I>&gt;<i> TreePath path = new TreePath(e.Path);
</I>&gt;<i>
</I>&gt;<i> // Try to write the new entry to the field and start
</I>&gt;<i> // to crash awfully when using static
</I>&gt;<i> store.GetIter(out iterator, path);
</I>&gt;<i> store.SetValue(iterator, 0, e.NewText);
</I>&gt;<i> }
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> static void Window_Deleted (object o, DeleteEventArgs e){
</I>&gt;<i> Application.Quit();
</I>&gt;<i> }
</I>&gt;<i> }
</I>&gt;<i>
</I>&gt;<i> ** SNIP: CODE ENDS HERE
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> which gives me a crying compiler like this:
</I>&gt;<i>
</I>&gt;<i> ** SNIP: STARTS CRYING HERE
</I>&gt;<i>
</I>&gt;<i> <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">andre at gremLin</A>:~/programming/mono/IndexTool$ mcs -pkg:gtk-sharp
</I>&gt;<i> TreeViewTryOut.csTreeViewTryOut.cs(27) error CS0103: The name `v' could
</I>&gt;<i> not be found in `MainClass'
</I>&gt;<i> TreeViewTryOut.cs(67) warning CS0219: The variable 'iterator' is
</I>&gt;<i> assigned but its value is never used
</I>&gt;<i> TreeViewTryOut.cs(84) error CS0120: An object reference is required for
</I>&gt;<i> the non-static field `store'
</I>&gt;<i> TreeViewTryOut.cs(85) error CS0120: An object reference is required for
</I>&gt;<i> the non-static field `store'
</I>&gt;<i> TreeViewTryOut.cs(15) warning CS0169: The private field
</I>&gt;<i> 'MainClass.store' is never used
</I>&gt;<i> Compilation failed: 3 error(s), 2 warnings
</I>&gt;<i>
</I>&gt;<i> ** SNIP: STOPS CRYING HERE
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> I think the problem so far is, that my store variable is used in Main
</I>&gt;<i> which is static. But when i make store static and edit some entry the
</I>&gt;<i> program crashes hard like:
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> ** SNIP: BAD CRASH STARTS HERE
</I>&gt;<i>
</I>&gt;<i> <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">andre at gremLin</A>:~/programming/mono/IndexTool$ mono TreeViewTryOut.exe
</I>&gt;<i>
</I>&gt;<i> Unhandled Exception: System.Reflection.TargetInvocationException:
</I>&gt;<i> Exception has been thrown by the target of an invocation. ---&gt;
</I>&gt;<i> System.NullReferenceException: Object reference not set to an instance
</I>&gt;<i> of an object
</I>&gt;<i> in &lt;0x0004d&gt; MainClass:Word_Edited (System.Object o, Gtk.EditedArgs e)
</I>&gt;<i> in &lt;0x00000&gt; &lt;unknown method&gt;
</I>&gt;<i> in (wrapper managed-to-native)
</I>&gt;<i> System.Reflection.MonoMethod:InternalInvoke (object,object[])
</I>&gt;<i> in &lt;0x0006f&gt; System.Reflection.MonoMethod:Invoke (System.Object obj,
</I>&gt;<i> BindingFlags invokeAttr, System.Reflection.Binder binder,
</I>&gt;<i> System.Object[] parameters, System.Globalization.CultureInfo culture)---
</I>&gt;<i> End of inner exception stack trace ---
</I>&gt;<i>
</I>&gt;<i> in &lt;0x00104&gt; System.Reflection.MonoMethod:Invoke (System.Object obj,
</I>&gt;<i> BindingFlags invokeAttr, System.Reflection.Binder binder,
</I>&gt;<i> System.Object[] parameters, System.Globalization.CultureInfo culture)
</I>&gt;<i> in &lt;0x00017&gt; System.Reflection.MethodBase:Invoke (System.Object obj,
</I>&gt;<i> System.Object[] parameters)
</I>&gt;<i> in &lt;0x000b3&gt; System.Delegate:DynamicInvokeImpl (System.Object[] args)
</I>&gt;<i> in &lt;0x00028&gt; System.MulticastDelegate:DynamicInvokeImpl (System.Object[]
</I>&gt;<i> args)
</I>&gt;<i> in &lt;0x0000e&gt; System.Delegate:DynamicInvoke (System.Object[] args)
</I>&gt;<i> in &lt;0x00147&gt;
</I>&gt;<i> GtkSharp.voidObjectstringstringSignal:voidObjectstringstringCallback
</I>&gt;<i> (IntPtr arg0, System.String arg1, System.String arg2, Int32 key)
</I>&gt;<i> in (wrapper native-to-managed)
</I>&gt;<i> GtkSharp.voidObjectstringstringSignal:voidObjectstringstringCallback
</I>&gt;<i> (intptr,intptr,intptr,int)
</I>&gt;<i> in &lt;0x00000&gt; &lt;unknown method&gt;
</I>&gt;<i> in (wrapper managed-to-native) Gtk.Application:gtk_main ()
</I>&gt;<i> in &lt;0x00007&gt; Gtk.Application:Run ()
</I>&gt;<i> in &lt;0x00370&gt; MainClass:Main (System.String[] args)
</I>&gt;<i>
</I>&gt;<i> ** SNIP: BAD CRASH ENDS HERE
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> Any ideas? I am justing starting with mono and gtk# and so far i like it
</I>&gt;<i> a lot but i have so much to learn before stopping to ask newbie
</I>&gt;<i> questions :-/
</I>&gt;<i>
</I>&gt;<i> I hope this big post is somehow easy to read. I edited a bit in
</I>&gt;<i> evolution so it was more readable for me. Hope that didn't kill the
</I>&gt;<i> formating information.
</I>&gt;<i>
</I>&gt;<i> Please help and Greetings
</I>&gt;<i> Andr&#233;
</I>&gt;<i>
</I>&gt;<i> _______________________________________________
</I>&gt;<i> Gtk-sharp-list maillist - <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">Gtk-sharp-list at lists.ximian.com</A>
</I>&gt;<i> <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">http://lists.ximian.com/mailman/listinfo/gtk-sharp-list</A>
</I>&gt;<i>
</I>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="006327.html">[Gtk-sharp-list] Problems with TreeView
</A></li>
<LI>Next message: <A HREF="006340.html">[Gtk-sharp-list] Problems with TreeView
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#6339">[ date ]</a>
<a href="thread.html#6339">[ thread ]</a>
<a href="subject.html#6339">[ subject ]</a>
<a href="author.html#6339">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">More information about the Gtk-sharp-list
mailing list</a><br>
</body></html>