[Gtk-sharp-list] different color rows for GtkTreeView
Adam Tauno Williams
adam at morrison-ind.com
Sun Apr 27 09:06:35 EDT 2008
> I think this is appropriate material for this list. I'm trying to have
> a TreeView with a ListStore have rows that are different colors. I'm
> pretty sure it's possible, because it looks like it's the case with
> MonoDevelop s and User Tasks/Comments. The question is, how?
> (Point of clarity: First row be red, second row be green -- that's
> all. I guess more generally, how do you control the row color as
> opposed to the column color)
You can set the colors and styles used by the cells of the list. See
the Effect(...) method in
Note: GUI is just a static class that can store colors for keys,
results of ColorForKey is a Gdk.Color.
So far the only way I can find to do this is to have a custom renderer
for each cell, setup like -
objectIdColumn = new Gtk.TreeViewColumn ();
cell = new Gtk.CellRendererText ();
objectIdColumn.SetCellDataFunc(cell, new Gtk.TreeCellDataFunc(RenderObjectId));
- and RenderObjectId looks like -
protected virtual void RenderObjectId(
Task task = IterTask(_model, _iter); // just returns the object for this iter
if(task == null)
(_cell as Gtk.CellRendererText).Text = task.ObjectId.ToString();
Effect(_model, _iter, (_cell as Gtk.CellRendererText), task);
- calling Effect(...) applies the effect based on row number [odd vs. even], etc...
It is a code-heavy solution but it works very well and is the only I've found to really control the look of the view.
More information about the Gtk-sharp-list