зеркало из https://github.com/mono/mail-archives.git
273 строки
11 KiB
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é Kuntze wrote:
|
|
><i> Hi everybody,
|
|
</I>><i>
|
|
</I>><i> i am trying to do the following in mono using c# and gtk#: Having a
|
|
</I>><i> simple two column list with word and numbers. When you edit one field in
|
|
</I>><i> any column, write the new text into the edited field.
|
|
</I>><i>
|
|
</I>><i> This must sound so newbish but i am struggeling with this a few hours
|
|
</I>><i> now and so i decided to ask some people in the know. Til now i got this:
|
|
</I>><i>
|
|
</I>><i> ** SNIP: CODE STARTS HERE
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> /*
|
|
</I>><i> * Filename: TreeViewTryOut.cs
|
|
</I>><i> * Date: 15.08.2005
|
|
</I>><i> *
|
|
</I>><i> * Description: This program is a TryOut for the editable
|
|
</I>><i> * TreeView - widget.
|
|
</I>><i> * The rows in the TreeView are editable and should
|
|
</I>><i> * take the new value, when entered.
|
|
</I>><i> */
|
|
</I>><i>
|
|
</I>><i> using System;
|
|
</I>><i> using Gtk;
|
|
</I>><i>
|
|
</I>><i> class MainClass{
|
|
</I>><i>
|
|
</I>><i> // Make the variable store visible to the whole class to use it
|
|
</I>><i> // in the code for the Edited event
|
|
</I>><i> ListStore store;
|
|
</I>><i>
|
|
</I>><i> public static void Main(string [] args){
|
|
</I>><i> Application.Init();
|
|
</I>><i>
|
|
</I>><i> // Definition of my window, which contains the editable
|
|
</I>><i> // Two - Column - List
|
|
</I>><i> Window window = new Window ("TreeView");
|
|
</I>><i> window.DeleteEvent += Window_Deleted;
|
|
</I>><i>
|
|
</I>><i> VBox vertBox = new VBox();
|
|
</I>><i> vertBox.BorderWidth = 6;
|
|
</I>><i>
|
|
</I>><i> window.Add(vertBox);
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> // Definition of my TreeView
|
|
</I>><i> TreeView treeView = new TreeView();
|
|
</I>><i> treeView.HeadersVisible = true;
|
|
</I>><i>
|
|
</I>><i> vertBox.Add(treeView);
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> // Definition of the colums
|
|
</I>><i> TreeViewColumn column = new TreeViewColumn();
|
|
</I>><i> column.Title = "Word";
|
|
</I>><i> CellRendererText colText = new CellRendererText();
|
|
</I>><i>
|
|
</I>><i> // Here i add the editable flag and the Edited event
|
|
</I>><i> colText.Editable = true;
|
|
</I>><i> colText.Edited += Word_Edited;
|
|
</I>><i> column.PackStart (colText, true);
|
|
</I>><i> column.AddAttribute (colText, "text", 0);
|
|
</I>><i> treeView.AppendColumn (column);
|
|
</I>><i>
|
|
</I>><i> column = new TreeViewColumn();
|
|
</I>><i> column.Title = "Page";
|
|
</I>><i> colText = new CellRendererText();
|
|
</I>><i>
|
|
</I>><i> // Here i add the editable flag and the Edited event
|
|
</I>><i> colText.Editable = true;
|
|
</I>><i> colText.Edited += Word_Edited;
|
|
</I>><i> column.PackStart (colText, true);
|
|
</I>><i> column.AddAttribute (colText, "text", 1);
|
|
</I>><i> treeView.AppendColumn (column);
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> // Definition of the field types
|
|
</I>><i> ListStore store = new ListStore (typeof (string), typeof
|
|
</I>><i> (string));
|
|
</I>><i> treeView.Model = store;
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> // Putting stuff in the list
|
|
</I>><i> TreeIter iterator = new TreeIter();
|
|
</I>><i> iterator = store.AppendValues("ChangeMe", "1");
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> // Show the not working stuff :-/
|
|
</I>><i> window.ShowAll();
|
|
</I>><i> Application.Run();
|
|
</I>><i> }
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> // My not working code, when a field is edited
|
|
</I>><i> static void Word_Edited (object o, EditedArgs e){
|
|
</I>><i> // When edited get me the current field
|
|
</I>><i> TreeIter iterator;
|
|
</I>><i> TreePath path = new TreePath(e.Path);
|
|
</I>><i>
|
|
</I>><i> // Try to write the new entry to the field and start
|
|
</I>><i> // to crash awfully when using static
|
|
</I>><i> store.GetIter(out iterator, path);
|
|
</I>><i> store.SetValue(iterator, 0, e.NewText);
|
|
</I>><i> }
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> static void Window_Deleted (object o, DeleteEventArgs e){
|
|
</I>><i> Application.Quit();
|
|
</I>><i> }
|
|
</I>><i> }
|
|
</I>><i>
|
|
</I>><i> ** SNIP: CODE ENDS HERE
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> which gives me a crying compiler like this:
|
|
</I>><i>
|
|
</I>><i> ** SNIP: STARTS CRYING HERE
|
|
</I>><i>
|
|
</I>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">andre at gremLin</A>:~/programming/mono/IndexTool$ mcs -pkg:gtk-sharp
|
|
</I>><i> TreeViewTryOut.csTreeViewTryOut.cs(27) error CS0103: The name `v' could
|
|
</I>><i> not be found in `MainClass'
|
|
</I>><i> TreeViewTryOut.cs(67) warning CS0219: The variable 'iterator' is
|
|
</I>><i> assigned but its value is never used
|
|
</I>><i> TreeViewTryOut.cs(84) error CS0120: An object reference is required for
|
|
</I>><i> the non-static field `store'
|
|
</I>><i> TreeViewTryOut.cs(85) error CS0120: An object reference is required for
|
|
</I>><i> the non-static field `store'
|
|
</I>><i> TreeViewTryOut.cs(15) warning CS0169: The private field
|
|
</I>><i> 'MainClass.store' is never used
|
|
</I>><i> Compilation failed: 3 error(s), 2 warnings
|
|
</I>><i>
|
|
</I>><i> ** SNIP: STOPS CRYING HERE
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> I think the problem so far is, that my store variable is used in Main
|
|
</I>><i> which is static. But when i make store static and edit some entry the
|
|
</I>><i> program crashes hard like:
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> ** SNIP: BAD CRASH STARTS HERE
|
|
</I>><i>
|
|
</I>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">andre at gremLin</A>:~/programming/mono/IndexTool$ mono TreeViewTryOut.exe
|
|
</I>><i>
|
|
</I>><i> Unhandled Exception: System.Reflection.TargetInvocationException:
|
|
</I>><i> Exception has been thrown by the target of an invocation. --->
|
|
</I>><i> System.NullReferenceException: Object reference not set to an instance
|
|
</I>><i> of an object
|
|
</I>><i> in <0x0004d> MainClass:Word_Edited (System.Object o, Gtk.EditedArgs e)
|
|
</I>><i> in <0x00000> <unknown method>
|
|
</I>><i> in (wrapper managed-to-native)
|
|
</I>><i> System.Reflection.MonoMethod:InternalInvoke (object,object[])
|
|
</I>><i> in <0x0006f> System.Reflection.MonoMethod:Invoke (System.Object obj,
|
|
</I>><i> BindingFlags invokeAttr, System.Reflection.Binder binder,
|
|
</I>><i> System.Object[] parameters, System.Globalization.CultureInfo culture)---
|
|
</I>><i> End of inner exception stack trace ---
|
|
</I>><i>
|
|
</I>><i> in <0x00104> System.Reflection.MonoMethod:Invoke (System.Object obj,
|
|
</I>><i> BindingFlags invokeAttr, System.Reflection.Binder binder,
|
|
</I>><i> System.Object[] parameters, System.Globalization.CultureInfo culture)
|
|
</I>><i> in <0x00017> System.Reflection.MethodBase:Invoke (System.Object obj,
|
|
</I>><i> System.Object[] parameters)
|
|
</I>><i> in <0x000b3> System.Delegate:DynamicInvokeImpl (System.Object[] args)
|
|
</I>><i> in <0x00028> System.MulticastDelegate:DynamicInvokeImpl (System.Object[]
|
|
</I>><i> args)
|
|
</I>><i> in <0x0000e> System.Delegate:DynamicInvoke (System.Object[] args)
|
|
</I>><i> in <0x00147>
|
|
</I>><i> GtkSharp.voidObjectstringstringSignal:voidObjectstringstringCallback
|
|
</I>><i> (IntPtr arg0, System.String arg1, System.String arg2, Int32 key)
|
|
</I>><i> in (wrapper native-to-managed)
|
|
</I>><i> GtkSharp.voidObjectstringstringSignal:voidObjectstringstringCallback
|
|
</I>><i> (intptr,intptr,intptr,int)
|
|
</I>><i> in <0x00000> <unknown method>
|
|
</I>><i> in (wrapper managed-to-native) Gtk.Application:gtk_main ()
|
|
</I>><i> in <0x00007> Gtk.Application:Run ()
|
|
</I>><i> in <0x00370> MainClass:Main (System.String[] args)
|
|
</I>><i>
|
|
</I>><i> ** SNIP: BAD CRASH ENDS HERE
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> Any ideas? I am justing starting with mono and gtk# and so far i like it
|
|
</I>><i> a lot but i have so much to learn before stopping to ask newbie
|
|
</I>><i> questions :-/
|
|
</I>><i>
|
|
</I>><i> I hope this big post is somehow easy to read. I edited a bit in
|
|
</I>><i> evolution so it was more readable for me. Hope that didn't kill the
|
|
</I>><i> formating information.
|
|
</I>><i>
|
|
</I>><i> Please help and Greetings
|
|
</I>><i> André
|
|
</I>><i>
|
|
</I>><i> _______________________________________________
|
|
</I>><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>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">http://lists.ximian.com/mailman/listinfo/gtk-sharp-list</A>
|
|
</I>><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>
|