[Gtk-sharp-list] How to display data from a SQLite database into a GTK# TreeView?

NPcomplete kzvezdarov at gmail.com
Thu Apr 28 19:17:25 EDT 2011


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. I find it extremely strange that there is no
documentation on the subject. 
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_set_cell_data_func:
assertion `info != NULL' failed

Here is my code:

public void SetupUsers(Gtk.TreeView table)
		{
		        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 < TblExaminees.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].SetCellDataFunc(new Gtk.CellRendererText(), new
Gtk.TreeCellDataFunc(renderExaminee));
					
				}
				list.AppendValues(rowData);
			
				
			}
			table.Model = list;
			reader.Close();
			cmd.Connection.Close();
			
		}
		
		protected void renderUser(Gtk.TreeViewColumn column, Gtk.CellRenderer
cell, Gtk.TreeModel model, Gtk.TreeIter iter)
		{
			Console.WriteLine("got here");
			(cell as Gtk.CellRendererText).Text = (string)model.GetValue(iter,
Array.FindIndex(TblUsers.SCHEMA, item => item == column.Title ));
		}
I appreciate your help. 

P.S. I have tried to use table.Columns[index].AddAttribute(new
Gtk.CellRendererText(), "text", index); instead of setting the data func,
which just returns this similar error: Gtk-CRITICAL **:
gtk_tree_view_column_cell_layout_add_attribute: assertion `info != NULL'
failed

--
View this message in context: http://mono.1490590.n4.nabble.com/How-to-display-data-from-a-SQLite-database-into-a-GTK-TreeView-tp3482522p3482522.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.


More information about the Gtk-sharp-list mailing list