[Gtk-sharp-list] CellRendererToggle Help!

Joe Scaduto scooch@noggle.biz
Fri, 16 Apr 2004 01:41:11 -0400


On Fri, 2004-04-16 at 00:19, John Luke wrote:
> On Thu, 2004-04-15 at 23:10 -0400, Joe Scaduto wrote:
> > Hello,
> > 
> > I currently have a ListStore with 3 columns appended and one whose
> > CellRenderer is CellRendererToggle.  Since the CellRendererToggle is for
> > the entire column I am not quite sure how to change the state of one of
> > the checkboxes.  The following code updates the value in the store for
> > the appropriate cell but the check box does not reflect this; either it
> > stays checked or does not.  Any help would be greatly appreciated.
> > 
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                      
> > public void SelectCommunity(object obj, ToggledArgs e)
> > {                       
> >     TreeModel listModel = treeview.Model;
> >     TreeIter iter;
> >  
> >     listModel.GetIterFromString(out iter, e.Path);
> >  
> >     bool check = (bool)listModel.GetValue(iter,0);
> > 
> >     if (check == false)
> >        communityStore.SetValue(iter,0,true);
> >     else
> >        communityStore.SetValue(iter,0,false);
> >          
> >     treeview.Model = communityStore;
> > }
> > 
> 
> I always forget how to do this myself, but GtkDemo uses this and perhaps
> it could help you. I think it's something simple like setting the column
> Activatable or something. See gtk-sharp/samples/GtkDemo/

John,

I already have the Activatable property set.  I went to the demo to see
what I could find and there was an example there and heres the code.....

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //FIXME: Finish implementing this function, I don't know
 //       why it doesn't work.
 private void ItemToggled (object o, ToggledArgs args)
 {
     Gtk.TreeIter iter;
     if (store.GetIterFromString(out iter, args.Path))
     {
         bool val = (bool) store.GetValue(iter, 0);
         Console.WriteLine("toggled {0} with value {1}",
args.Path, val);
         
         store.SetValue(iter, 0, !val);
     }
 }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As you can see the code logic is the same as mine just cleaner.  
Do you have any other suggestions?   

Thanks,

Joe