[Gtk-sharp-list] SOLUTION: Changing row properties (like color and weight) in a TreeView.

Jason Boutwell jason.boutwell@comcast.net
08 Sep 2003 10:40:28 -0400


Here's a code snippet for changing tree view row attributes like color
and font:

TreeViewColumn col = new TreeViewColumn("Title Column", new
CellRendererText (), "text", 0, "weight", 1);
TreeStore store = new TreeStore (typeof (string), typeof (int));
int weight = (int) Pango.Weight.Bold; 
store.AppendValues("Item Title", weight);

You create the tree view column using the constructor that accepts
attributes (or use the AddAttribute method, if you prefer). The KEY to
getting it to work (pun intended) is to make sure that the name of the
attribute is the same as the name of the cell renderer property that you
want to change (in my case, the Weight property). It's very
JavaBean-like.

Then I used a ButtonReleaseEventHandler to change my text from bold to
normal when I select the row. (I would prefer a RowSelectedEventHandler,
but that's a quibble for another thread.)

int weight = (int) Pango.Weight.Normal;
store.AppendValues("Item Title", weight);

Here's a screenshot of my RSS app with the working TreeView:
http://www.jboutwell.com/weblog/monoreader.jpg

It's really quite simple. There just aren't any docs that explain how to
do it, so it took quite a bit of fiddling.

Hope that helps.

Jason


On Wed, 2003-09-03 at 15:32, Jason Boutwell wrote:
> Ixnay on that last question.
> 
> I finally figured out how to properly use the attributes of a cell
> renderer.
> 
> Jason
> 
> 
> On Wed, 2003-09-03 at 11:28, Jason Boutwell wrote:
> > Mike.
> > 
> > Thanks for the quick reply!
> > 
> > I ran across a few mails in the list that mention binding Colors in the
> > TreeView and then setting the Renderer, however I've been over and over
> > the API, and cannot seem to find the proper methods that suit this
> > purpose. Could you perhaps give me a quick snippet of code that
> > illustrates what you mean, or point me to the relevant API calls?
> > 
> > I appreciate your help.
> > 
> > Jason
> > 
> > 
> > On Tue, 2003-09-02 at 23:44, Mike Kestner wrote:
> > > On Tue, 2003-09-02 at 14:49, Jason Boutwell wrote:
> > > 
> > > > I need the ability to change the foreground color (text color) of
> > > > individual rows in my TreeView(s). Is there a way to do this? I see that
> > > > I can alter the foreground of CellRendererText objects, but I do not see
> > > > how I can access these renderer(s) on a per-row basis.
> > > 
> > > You need to add a color column to your tree/list store and bind it to
> > > the color property on the cell renderer.
> > 
> > _______________________________________________
> > Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list