[Gtk-sharp-list] Arbitrary number of columns in Gtk.ListStore
Xavier de Blas
xaviblas at cvs.gnome.org
Mon May 22 20:20:12 EDT 2006
Hello Arthur
If i understood what you ask, i do something similar with a TreeStore
I do it like this:
public TreeViewEvent (Gtk.TreeView treeview, int newPrefsDigitsNumber)
{
/*
...
*/
//sample for 4 columns
string [] columnsString = { "firstCol", "secondCol", "thirdCol", "fourthCol" };
store = getStore(columnsString.Length);
treeview.Model = store;
prepareHeaders(columnsString);
}
protected TreeStore getStore (int columns)
{
//prepares the TreeStore for required columns
Type [] types = new Type [columns];
for (int i=0; i < columns; i++) {
types[i] = typeof (string);
}
TreeStore myStore = new TreeStore(types);
return myStore;
}
protected virtual void prepareHeaders(string [] columnsString)
{
treeview.HeadersVisible=true;
int i=0;
foreach(string myCol in columnsString) {
treeview.AppendColumn (myCol, new CellRendererText(), "text", i++);
}
}
This code is adapted from here:
http://cvs.gnome.org/viewcvs/chronojump/src/treeViewEvent.cs?rev=1.1&view=log
belonging to chronojump:
http://gnome.org/projects/chronojump
I hope it helps
sorry i sent to you this a few times, i was asleep ;)
On dl, 2006-05-22 at 20:35 -0400, Arthur Turrini wrote:
> Hello guys,
>
> I'm new to gtk# and to this mailing list.
>
> What I'm trying to do is to create a new ListStore with an arbitrary
> number of columns, instead of using
>
> ls = new Gtk.ListStore(typeof(string), ... , typeof(bool));
>
> I wanted something like:
>
> ... code begins
> ls = new Gtk.ListStore();
> ... some code
> ls.AppendColumnType(typeof(string));
> ... some more appends
> ls.AppendColumnType(typeof(bool));
> ... rest of code
>
> Does anyone knows how I can achieve this in a pratical non-obstructive
> way?
>
> Thanks to everyone!
>
> [ ]'s,
>
> ---
> Arthur Turrini.
>
>
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
More information about the Gtk-sharp-list
mailing list