Christian Rudh a �crit :

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

Thanks for your answer. I received an e-mail advising me to have a look at the source of http://veldstra.co.uk/sharplist/. Thanks to this code, I wrote the following :

// Build the List
jobsStore = new ListStore (typeof (string), typeof (string), typeof (string), typeof (int), typeof (int), typeof(string), typeof(string));
tv = new TreeView ();
tv.Model = jobsStore;
tv.HeadersVisible = true;
tv.RulesHint = true;
tv.Reorderable = true;


// Category column
CellRendererText crt1 = new CellRendererText();
TreeViewColumn col1 = new TreeViewColumn ("Categorie", crt1, "text", 0); col1.AddAttribute (crt1, "weight", 3);
col1.AddAttribute (crt1, "style", 4);
col1.AddAttribute (crt1, "foreground", 5);
col1.AddAttribute (crt1, "background", 6);
tv.AppendColumn(col1);
// Job column
CellRendererText crt2 = new CellRendererText();
TreeViewColumn col2 = new TreeViewColumn ("Job", crt2, "text", 1);
col2.AddAttribute (crt2, "weight", 3);
col2.AddAttribute (crt2, "style", 4);
col2.AddAttribute (crt2, "foreground", 5);
col2.AddAttribute (crt2, "background", 6);
tv.AppendColumn(col2);
// State column
CellRendererText crt3 = new CellRendererText();
TreeViewColumn col3 = new TreeViewColumn ("Etat", crt3, "text", 2);
col3.AddAttribute (crt3, "weight", 3);
col3.AddAttribute (crt3, "style", 4);
col3.AddAttribute (crt3, "foreground", 5);
col3.AddAttribute (crt3, "background", 6);
tv.AppendColumn(col3);


       tv.Selection.Changed += new EventHandler (OnSelectionChanged);
       sw.Add(tv);
       tv.Show();

And then to browse and change one of the lines parameter :

       TreeIter iter;
       TreeModel model;
       ArrayList jobsToDownloadAgain = new ArrayList();
       if (jobsStore.GetIterFirst(out iter))
       {
           do
           {
                   // Job has not been copied, its state is NOK and bgd red
                   jobsStore.SetValue (iter, 2, "Done");
                   jobsStore.SetValue (iter, 6, "red");
           }
           while (jobsStore.IterNext(ref iter));
       }

But in my case, I needed to browse the rows, where in your code you don't...

Thanks a lot,
Vincent
_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to