[Gtk-sharp-list] TreeView & custom colors for nodes, bad alignment

vbtricks vbtricks at gmx.net
Mon Aug 4 13:29:57 EDT 2008


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
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,


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
		this.treeview1.HeadersVisible = false;

		TreeIter iter = this.folderStore.AppendValues(new FolderItem("root",
		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.

More information about the Gtk-sharp-list mailing list