OS: openSuse 11.4
IDE: MonoDevelop 2.4.2
using GTK#
I need to display the datatable of a sqlite database in a simple grid view, much like in WindowsForms’/WPF’s datagridview, but with GTK#.
I have been trying to configure the GTK.TreeView to display the data properly, but with no luck. The data is not displayed and I get an obscure error in the Application output. Here is my code:
Type[] types;
SqliteCommand cmd = new SqliteCommand("SELECT * FROM "+Tables.USERS, _cddapConn);
cmd.Connection.Open();
SqliteDataReader reader = cmd.ExecuteReader();
types = new Type[reader.FieldCount];
for(int i = 0; i < types.Length; i++)
types[i] = typeof(string);
Gtk.ListStore list = new Gtk.ListStore(types);
for(int i = 0; i < TblUsers.SCHEMA.Length; i++)
{
table.AppendColumn(TblUsers.SCHEMA[i], new Gtk.CellRendererText(), "text");
}
while(reader.Read())
{
String[] rowData = new String[TblUsers.SCHEMA.Length];
for(int index = 0; index < TblUsers.SCHEMA.Length; index++)
{
rowData[index] = reader.GetString(index);
table.Columns[index].AddAttribute(new Gtk.CellRendererText(), "text", index);
}
list.AppendValues(rowData);
}
table.Model = list;
reader.Close();
cmd.Connection.Close();
I followed the example given here: http://www.mono-project.com/GtkSharp_TreeView_Tutorial.
First I create the model (ListStore) by initializing it with the string type for the data of every column. Then I append the columns of the data table to the tree view. Then I engage the sqlite reader, and for every entry I add its data to the model. Then I add a cell for each column pointing to the data. Finally, I give the tree view its model.
However, this only manages to display the columns with no data. What I get in the application output is this:
Gtk-CRITICAL **: gtk_tree_view_column_cell_layout_add_attribute: assertion `info != NULL' failed
I spent a few hours looking for any information about this problem with no success. What is surprising is that I found no examples of the treeview being used in mono to display data from a database, or any documentation on gtk# for that matter.
How can I make my grid view work? I really only need it to display the data and accept row selections (so that I can check the ID column of the selected row).
I saw the very same as you, Following the GtkSharp TreeView Tutorial gives the exact same assertion and no data in the tree. I think the Assert is a red herring. In any case, I got what you were aiming for with the following code.