Salut, I'm trying to display a folder structure in a treeview. Some of the folders shall be displayed grayed out. I found the tutorial at http://www.mono-project.com/GtkSharp_TreeView_Tutorial#Controlling_how_the_model_is_used which works quite fine if the tree displayed in the TreeView has only one layer. However if there are more layers than in the example below, the captions appear badly aligned. Any idea how to solve this?
Thanks in advance, Stefan using System; using Gtk; public partial class MainWindow: Gtk.Window { private class FolderItem { private string name; private bool drawGray; public FolderItem(string name, bool drawGray) { this.name = name; this.drawGray = drawGray; } public bool DrawGray { get { return this.drawGray; } } public string Name { get { return this.name; } } } private TreeStore folderStore; public MainWindow (): base (Gtk.WindowType.Toplevel) { Build (); this.folderStore = new TreeStore(typeof(FolderItem)); this.treeview1.Model = this.folderStore; TreeViewColumn nameColumn2 = new TreeViewColumn("Name", new CellRendererText(), "text", 0); Gtk.CellRendererText nameCell2 = new Gtk.CellRendererText (); nameColumn2.PackStart (nameCell2, false); nameColumn2.SetCellDataFunc(nameCell2, new Gtk.TreeCellDataFunc (RenderFolderName)); this.treeview1.AppendColumn(nameColumn2); this.treeview1.HeadersVisible = false; TreeIter iter = this.folderStore.AppendValues(new FolderItem("root", false)); this.folderStore.AppendValues(iter, new FolderItem("black", false)); this.folderStore.AppendValues(iter, new FolderItem("gray", true)); } private void RenderFolderName (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter) { FolderItem folderItem = (FolderItem) model.GetValue (iter, 0); if (!folderItem.DrawGray) { (cell as Gtk.CellRendererText).Foreground = "black"; } else { (cell as Gtk.CellRendererText).Foreground = "darkgray"; } (cell as Gtk.CellRendererText).Text = folderItem.Name; //(cell as Gtk.CellRendererText).Alignment = Pango.Alignment.Left; } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } } -- View this message in context: http://www.nabble.com/TreeView---custom-colors-for-nodes%2C-bad-alignment-tp18815856p18815856.html Sent from the Mono - Gtk# mailing list archive at Nabble.com. _______________________________________________ Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/gtk-sharp-list