[Gtk-sharp-list] How to search a TreeStore and use a CellRendererCombo?

Michael Hutchinson m.j.hutchinson at gmail.com
Sat Feb 27 23:21:07 EST 2010


On Sat, Feb 27, 2010 at 7:26 AM, a B <abcehooha at yahoo.com> wrote:
> Hello,
> 1) I'm trying to check if a specific string exists in a TreeStore (which
> contains strings). I tried using the Foreach method but I cannot send the
> string to the TreeModelForeachFunc which I created. What should I do?

Use the TreeIter to get the value from the TreeModel, i.e.

store.Foreach (delegate (TreeModel model, TreePath path, TreeIter iter) {
    var col0Value = (string) model.GetValue (iter, 0);
});

You can also walk the store directly:

TreeIter iter;
if (store.GetIterFirst (out iter)) {
    do {
        var col0Value = (string) store.GetValue (iter, 0);
    } while (store.IterNext (ref iter));
}

> 2) I want the cells in a specific column to be editable using a
> CellRendererCombo. How do I do it?

IIRC you must set Editable to true, and handle the Edited event, from
which you should update the store. Something like the following:

cellRenderer.Editable = true;
cellRenderer.Edited += delegate(object o, EditedArgs args) {
    TreeIter iter;
    if (store.GetIter (args.Path, out iter)) {
        store.SetValue (iter, 0, args.NewText);
        return true;
    }
    return false;
};


-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Gtk-sharp-list mailing list