[Gtk-sharp-list] TreeView nightmares
Luciano _
lnc19 at hotmail.com
Wed Mar 14 10:18:52 EDT 2007
I'm not really sure if i understand you, but i guess:
If you wish to have an index in a ListStore, simple add a new column (not
visible) with a subsequent number. Or maybe a better solution is to add your
Object (the one that you want to refer) to the ListStore, some simple
example:
// The ListStore
ListStore panelStore = new ListStore(typeof(string), typeof(string),
typeof(CustomObject), typeof(int));
myTreeView.AppendColumn("Description 1", new CellRendererText(), "text", 0);
myTreeView.AppendColumn("Description 2", new CellRendererText(), "text", 1);
myTreeView.Model = panelStore;
// Add items
panelStore.AppendValues("Item 1", "My Item 1", new object(), 0);
panelStore.AppendValues("Item 2", "My Item 2", new object(), 1);
I don't remember which is the event to get the Double Click on a Treeview,
but, inside of it, you have to do this:
TreeIter iter;
if(myTreeView.Selection.GetSelected(out iter)) {
Console.WriteLine((string)myTreeView.Model.GetValue(iter, 0)) // The
first description
Console.WriteLine((string)myTreeView.Model.GetValue(iter, 1)) // The
second description
object myObject = (object)myTreeView.Model.GetValue(iter, 2) // My Object
int idx = (object)myTreeView.Model.GetValue(iter, 3) // The index
}
If you wish to get all of the Iters (and all of the values) of your Model,
try this:
TreeIter iter;
TreeModel model = myTreeView.Model;
ListStore store = ((ListStore)model);
if(store.GetIterFirst(out iter))
do
{
Console.WriteLine((string)myTreeView.Model.GetValue(iter, 0)) // The
first description
Console.WriteLine((string)myTreeView.Model.GetValue(iter, 1)) // The
second description
object myObject = (object)myTreeView.Model.GetValue(iter, 2) // My
Object
int idx = (object)myTreeView.Model.GetValue(iter, 3) // The index
}while(store.IterNext(ref iter));
I hope it helps :)
Luciano
>From: Aaron Oxford <aaron at hardwarehookups.com.au>
>To: gtk-sharp-list at lists.ximian.com
>Subject: [Gtk-sharp-list] TreeView nightmares
>Date: Wed, 14 Mar 2007 23:50:40 +1100
>MIME-Version: 1.0
>Received: from lists.ximian.com ([130.57.169.22]) by
>bay0-mc1-f19.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed,
>14 Mar 2007 05:52:18 -0700
>Received: from galactus.ximian.com (localhost.localdomain [127.0.0.1])by
>lists.ximian.com (Postfix) with ESMTP id 26EB41CFB8B;Wed, 14 Mar 2007
>10:31:41 -0400 (EDT)
>Received: from herald.ximian.com (frontgate.ximian.com [130.57.169.19])by
>lists.ximian.com (Postfix) with ESMTP id 87BCF1CFB62for
><gtk-sharp-list at lists.ximian.com>;Wed, 14 Mar 2007 10:31:40 -0400 (EDT)
>Received: by herald.ximian.com (Postfix, from userid 2601)id 9F1A47009C;
>Wed, 14 Mar 2007 07:52:16 -0500 (EST)
>Received: from rs8.websiteswelcome.com (rs8.websiteswelcome.com
>[67.18.89.2])by herald.ximian.com (Postfix) with ESMTP id 9E3A870098for
><gtk-sharp-list at lists.ximian.com>;Wed, 14 Mar 2007 07:52:12 -0500 (EST)
>Received: from 10.224.233.220.exetel.com.au
>([220.233.224.10]:2768helo=innovative.hardwarehookups.com.au)by
>rs8.websiteswelcome.com with esmtpa (Exim 4.63)(envelope-from
><aaron at hardwarehookups.com.au>) id 1HRSwG-0006Tg-Rbfor
>gtk-sharp-list at lists.ximian.com; Wed, 14 Mar 2007 14:50:45 +0200
>X-Message-Info:
>LsUYwwHHNt0O91O8cgpZEJdXb0k+keNOcMTKsHNIWMwTLe5qTh/hhq/vQskezIQr
>X-Original-To: gtk-sharp-list at lists.ximian.com
>Delivered-To: gtk-sharp-list at lists.ximian.com
>X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0
>X-AntiAbuse: This header was added to track abuse,please include it with
>any abuse report
>X-AntiAbuse: Primary Hostname - rs8.websiteswelcome.com
>X-AntiAbuse: Original Domain - lists.ximian.com
>X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
>X-AntiAbuse: Sender Address Domain - hardwarehookups.com.au
>X-Source: X-Source-Args: X-Source-Dir: X-Spam-Checker-Version: SpamAssassin
>3.0.3 (2005-04-27) on frontgate.ximian.com
>X-Spam-Level: **
>X-Spam-Status: No, score=2.9 required=5.0
>tests=FORGED_RCVD_HELO,MY_OBFUX,SPF_HELO_PASS,SPF_PASS version=3.0.3
>X-BeenThere: gtk-sharp-list at lists.ximian.com
>X-Mailman-Version: 2.1.8
>Precedence: list
>List-Id: "Discussion of the .Net bindings for
>Gnome"<gtk-sharp-list.lists.ximian.com>
>List-Unsubscribe:
><http://lists.ximian.com/mailman/listinfo/gtk-sharp-list>,<mailto:gtk-sharp-list-request at lists.ximian.com?subject=unsubscribe>
>List-Archive: <http://lists.ximian.com/pipermail/gtk-sharp-list>
>List-Post: <mailto:gtk-sharp-list at lists.ximian.com>
>List-Help: <mailto:gtk-sharp-list-request at lists.ximian.com?subject=help>
>List-Subscribe:
><http://lists.ximian.com/mailman/listinfo/gtk-sharp-list>,<mailto:gtk-sharp-list-request at lists.ximian.com?subject=subscribe>
>Errors-To: gtk-sharp-list-bounces at lists.ximian.com
>Return-Path: gtk-sharp-list-bounces at lists.ximian.com
>X-OriginalArrivalTime: 14 Mar 2007 12:52:19.0039 (UTC)
>FILETIME=[99A636F0:01C76637]
>
>Hi again list,
>
>So how about these TreeViews... :-\ I can't figure out how to use
>one as an efficient view of an internal collection at all. Is there
>some way I can just interact directly with the objects in the list or
>the view? Sorry to ask so many newbie questions, but please help
>again - I'm *this* close to writing my own VBox of clickable Labels! :-)
>
>Thanks to everyone who replied RE threading. One more thing there, do
>I need to do anything special if I want to access a widget from a
>timeout callback? I'm still getting the odd crash, and I'm pretty
>sure the only thread running is the one doing the timeouts. I have
>other threads running but they are all separated from the GUI either
>completely or via the timeouts.
>
>Sorry for another long email, but here's the background for anyone
>who wants to reply:
>
>I got over the idea of having to keep a reference to the widget as
>well as the ListStore in order to do the basic operations. That
>almost made sense, but then it seemed that for something as simple as
>getting the value of the activated row in the RowActivated handler
>also requires an TreeIter on the store, and all you have is a Path,
>not a link to the widget or to the row data. What really bummed me
>was when I discovered that this iterater refuses to store and
>retrieve raw objects, complaining about its limited set of types and
>the fact that my index column data isn't one of them.
>
>Alright, ranting aside, how does one usually link the data in the
>ListStore back to other objects? All I'm trying to do here is operate
>a simple list of named internal objects that, when double clicked,
>cause further information to be displayed. I could iterate through my
>own list using some artifically generated index (which would then be
>displayed alongside the object's name) in order to link back to my
>internal objects, but I can't believe that's the way it was intended
>to be used.
>
>I've been through the Gtk API multiple times to no avail, and the SDK
>sample sucks - there's no interaction or even run-time modification
>of the list. Did I miss a simple [ ] indexing operator defined
>somewhere or what?
>
>Aaron.
>---------------------------------------------------------------------------------
>Aaron Oxford - aaron+hardwarehookups .com .au
>Director, Innovative Computer Solutions (Aust) Pty. Ltd.
>49 Maitland Rd, Mayfield, NSW 2304 Australia
>http://www.ic-solutions.com.au
>Developer, SourceForge project VioLet Composer
>http://sourceforge.net/projects/buzz-like
>
>_______________________________________________
>Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
_________________________________________________________________
¿Cuánto vale tu auto? Tips para mantener tu carro. ¡De todo en MSN Latino
Autos! http://latino.msn.com/autos/
More information about the Gtk-sharp-list
mailing list