[Gtk-sharp-list] Problems with custom treeview column
Mike Rhodes
mike.rhodes at gmail.com
Wed Jul 6 04:28:35 EDT 2005
Hi Matthew,
>
> //this one works:
> treeview.AppendColumn("Date Of Birth", new CellRendererText(), new
> TreeCellDataFunc(dateColumnFunction));
>
> //I think this one should work as well, but it isn't:
> TreeViewColumn tvc = new TreeViewColumn();
> tvc.Title = "Date Of Birth";
> tvc.SetCellDataFunc(new CellRendererText(), new
> TreeCellDataFunc(dateColumnFunction));
> treeview.AppendColumn(tvc);
I think you need to pack the cell renderer into the column to make
sure it is drawn, similar to this snippet:
CellRenderer cell; TreeViewColumn col;
col = new TreeViewColumn();
col.Title = "Item";
cell = new CellRendererPixbuf();
col.PackStart(cell, false); // *** pack renderer into column
col.SetCellDataFunc(cell, new TreeCellDataFunc(item_unread_dfunc));
treeview.AppendColumn(col);
In your two line version, I think that AppendColumn() does the packing
of the cell renderer for you.
> Also, as I mentioned before, eventually I would like to be able to sort
> by this column, probably needing a custom cell sorter function? Any help
> or direction will be greatly appreciated.
For sorting, you can probably use something like:
/* class var for sort */
private const int SORT_ID = 0;
/* in constructor */
// set sorting of the list up
list_store.SetSortFunc(SORT_ID, sort, (IntPtr)0, null);
list_store.SetSortColumnId(SORT_ID, SortType.Ascending);
The sort function signature is something like:
public int sort (TreeModel model, TreeIter a, TreeIter b)
{
// perform comparison here of a and b and return appropriately
}
Check the docs for SetSortFunc() and SetSortColumnId() for more info.
Mike.
--
"He who fights with monsters might take care
lest he thereby become a monster. And if you
gaze for long into an abyss, the abyss gazes
also into you." - Nietzsche
More information about the Gtk-sharp-list
mailing list