[Gtk-sharp-list] Few questions about how to use TreeView

Michael Hutchinson m.j.hutchinson at gmail.com
Thu Dec 31 13:38:42 EST 2009

On Thu, Dec 31, 2009 at 3:51 AM, Karthikeyan R
<karthikeyan_r at spanservices.com> wrote:
> Hi All,
> I have few questions about the Gtk.TreeView, my program is as same as the
> TreeView example provided here
> http://www.mono-project.com/GtkSharp_TreeView_Tutorial
> 1. How can I get the integer position of the selected TreeIter?

store.GetPath (iter) will get you a TreePath, which represents the
indexed position. TreePath.Indices is an array of integers
representing the position at each level. For example, if it's the
second child of the 3rd toplevel item, it would be { 2, 1 }.

> 2. How to remove the child nodes of selected TreeIter?
>     Currently I'm following the steps to achive this,
>         1. Get the parent Iter,
>         2. Create a newTreeIter with selectedTreeIter details, and remove
> the selectedTreeIter (this removes the child iter's)
>         3. Append the newTreeIter with the reference of parentIter
>         OR
>         2. InserftNodeAfter / InsertNodeBefore with sibling as
> selectedTreeIter to parentIter, this returns newIter, and remove the
> selectedIter
>         3. Set the column values for newIter
>     Is there any methods which I can use to remove the child iters of given
> treeIter?

The way I'd do it would be to get the number of children using
IterNChildren, move to the first child, then call Remove that many
times. Remove (ref iter) sets the inter to point to the next row.

something like

void RemoveChildren (TreeIter iter)
    int count = store.IterNChildren (next);
    if (store.IterNext (ref iter))
        while (count-- > 0 && store.Remove (ref iter));

> 3. How can I enumerate through the child iters? Wondering why there is no
> GetIterNext(Gtk.TreeIter selectedIter)?

Yeah, that one always gets me. It's called IterNext.

Michael Hutchinson

More information about the Gtk-sharp-list mailing list