[Gtk-sharp-list] treeview toggled not changing
George Farris
george@gmsys.com
14 Jun 2003 09:37:03 -0700
On Sat, 2003-06-14 at 05:42, Rachel Hestilow wrote:
> On Sat, 2003-06-14 at 01:27, George Farris wrote:
> > public void enabled_toggled (object o, GtkSharp.ToggledArgs args)
> > {
> > Console.WriteLine("toggled {0}", args);
> > }
> >
> > The enabled_toggled works when I click the little checkbox but the
> > actual gui state doesn't change when clicked, the check mark never
> > disappears. Is it supposed to be changed manually with the signal? I
> > would have thought it would just change when clicked.
>
> Hi George,
> The TreeView actually works differently here than you might expect.
> Since it is Model-View-Controller based, the view will never directly
> modify the model (in this case, toggling the actual boolean value).
> Instead you need to update the model value once you receive the toggled
> callback, like so:
>
> public void enabled_toggled (object o, GtkSharp.ToggledArgs args)
> {
> Console.WriteLine("toggled {0}", args);
>
> Gtk.TreeIter iter;
> if (store.GetIterFromString(out iter, args.Path))
> {
> bool val = (bool) store.GetValue(iter, 0);
> store.SetValue(iter, 0, !val);
> }
> }
>
> The view will receive a notification of the changed value and update
> the check mark accordingly.
Just for the record my function ended up looking like this:
public void enabled_toggled (object o, GtkSharp.ToggledArgs args)
{
Value val = new Value();
if (store.GetIterFromString(out iter, args.Path)) {
store.GetValue(iter, 0, out val);
Value valnot = new Value(!(bool)val);
store.SetValue(iter, 0, valnot);
}
}
--
George Farris <george@gmsys.com>