[Gtk-sharp-list] Row background color
Christian Rudh
lists-christian@rudh.se
Sat, 26 Feb 2005 19:52:27 +0100
Hi
I have an application where it makes some text in a treeview bold, but
it should be possible to use for setting the background too:
This is the column I set up in the beginning:
TreeViewColumn displayCol = new TreeViewColumn ();
CellRendererText displayRenderer = new CellRendererText ();
displayRenderer.Xpad = 10;
displayCol.Title = "Filedisplay";
displayCol.PackStart (displayRenderer, true);
displayCol.SetCellDataFunc (displayRenderer, new TreeCellDataFunc
(MarkUpSongName));
playList.AppendColumn (displayCol);
If you look at the SetCellDataFunc, it calls MarkUpSongName when there
is a redraw.
This is the method:
private void MarkUpSongName (TreeViewColumn treeColumn, CellRenderer
cellRenderer, TreeModel treeModel, TreeIter treeIter)
{
GLib.Value valx = new GLib.Value ();
store.GetValue (treeIter, 1, ref valx);
string completeName = (string) valx.Val;
GLib.Value valy = new GLib.Value ();
store.GetValue (treeIter, 0, ref valy);
string hiddenName = (string) valy.Val;
CellRendererText textCellRenderer = (CellRendererText) cellRenderer;
if (hiddenName == null)
{
store.SetValue (treeIter, 0, "x");
textCellRenderer.Markup = "";
}
else if (treeIter.Equals (nextToPlay))
{
textCellRenderer.Markup = "<b>" + completeName + "</b>";
}
else
{
textCellRenderer.Markup = completeName;
}
}
You should be able to change this function to set
textCellRenderer.Background instead of textCellRenderer.Markup if the
columns contain the correct text (red). Then you don't have to have a
function going through the rows, you simply wait for a redraw or call it
yourself with the QueueDraw method in the treeview.
I tried the background setting in my code and it worked fine.
/Christian
On Thu, 2005-02-24 at 18:15 +0100, Vincent Arnoux wrote:
> Hello,
> I have a TreeStore called jobsStore in a treeview and I would like to be
> able, when a button is clicked, to browse rows and change one row's
> background color.
> I found some answers in the mailing list, but none I can understand
> easily...
> I would like to do something like:
>
> void on_downloadJobsButton_clicked( object o, EventArgs args )
> {
> TreeIter iter;
> TreeModel model;
> if (jobsStore.GetIterFirst(out iter)) {
> do {
> if (jobsStore.GetValue(iter, 0).Equals("red") &&
> jobsStore.GetValue(iter, 1).Equals("red"));
> // Change this cell's background color
> }
> while (jobsStore.IterNext(ref iter));
> }
> }
>
>
> Thanks,
> Vincent
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
>
--
Christian Rudh <lists-christian@rudh.se>