Getting the string of the selected item of a TreeView

View: New views
5 Messages — Rating Filter:   Alert me  

Getting the string of the selected item of a TreeView

by SgtNasty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am trying to get the text of an item in a TreeView. The sample code
provides the following:

     static void OnCursorChanged(object obj, EventArgs e)
     {
          TreeSelection selection = (obj as TreeView).Selection;

          TreeModel model;
          TreeIter iter;

          // The iter will point to the selected row
          if(selection.GetSelected(out model, out iter))
          Console.WriteLine("Path of selected row = {0}",
model.GetPath(iter));
     }
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: Getting the string of the selected item of a TreeView

by Chris Howie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jul 21, 2009 at 2:38 PM, Ronaldo Nascimento<sgtnasty@...> wrote:
> I am trying to get the text of an item in a TreeView. The sample code
> provides the following:

Since you didn't provide any information about what you are actually
doing (not sample code) nor about what happened when you tried it,
it's not possible to determine what the problem is.

--
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: Getting the string of the selected item of a TreeView

by SgtNasty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, I am using the sample code almost as is.
the call to model.GetPath(iter) returns a 0, i was hoping for the text
there, but I see its the node index number.
I think I am getting the idea here.


On Tue, Jul 21, 2009 at 2:48 PM, Chris Howie<cdhowie@...> wrote:

> On Tue, Jul 21, 2009 at 2:38 PM, Ronaldo Nascimento<sgtnasty@...> wrote:
>> I am trying to get the text of an item in a TreeView. The sample code
>> provides the following:
>
> Since you didn't provide any information about what you are actually
> doing (not sample code) nor about what happened when you tried it,
> it's not possible to determine what the problem is.
>
> --
> Chris Howie
> http://www.chrishowie.com
> http://en.wikipedia.org/wiki/User:Crazycomputers
>
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: Getting the string of the selected item of a TreeView

by jago :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have you looked at http://code.google.com/p/holly-gtk-widgets/ for an
alternate TreeView?

On Tue, Jul 21, 2009 at 2:38 PM, Ronaldo Nascimento<sgtnasty@...> wrote:

> I am trying to get the text of an item in a TreeView. The sample code
> provides the following:
>
>     static void OnCursorChanged(object obj, EventArgs e)
>     {
>          TreeSelection selection = (obj as TreeView).Selection;
>
>          TreeModel model;
>          TreeIter iter;
>
>          // The iter will point to the selected row
>          if(selection.GetSelected(out model, out iter))
>                Console.WriteLine("Path of selected row = {0}",
> model.GetPath(iter));
>     }
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@...
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: Getting the string of the selected item of a TreeView

by Mike Kestner-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2009-07-21 at 14:38 -0400, Ronaldo Nascimento wrote:

> I am trying to get the text of an item in a TreeView. The sample code
> provides the following:
>
>      static void OnCursorChanged(object obj, EventArgs e)
>      {
>           TreeSelection selection = (obj as TreeView).Selection;
>
>           TreeModel model;
>           TreeIter iter;
>
>           // The iter will point to the selected row
>           if(selection.GetSelected(out model, out iter))
>           Console.WriteLine("Path of selected row = {0}",
> model.GetPath(iter));

                Console.WriteLine (model.GetValue (iter, 0));

Assuming you stored the string you want to print in column 0 of the
model.


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