[Gtk-sharp-list] Dynamic from SQLite popuplated Treeview mad editable

Sebastian exit at are-you-ready.de
Thu Aug 26 08:07:27 EDT 2010


Am Donnerstag, den 26.08.2010, 13:45 +0200 schrieb Rampage:
> Sebastian ha scritto:
> > Hey Guys,
> >
> > I'm writing my first gtk# Application just for learning. It should be a
> > simple DVD Managment Tool. I implemented a Treeview that gets its
> > Columns, Titles and Values dynamic from an SQLite DB. That works so far.
> > What I now want is a possibility to edit the Records within the
> > Treeview.
> > What I found out so far is that I make a Cell editable with the
> > following:
> > CellRendererText colr = new CellRendererText();
> > colr.Editable = true; 
> > colr.Edited += CellEdit;
> >
> > But then I have no clue what to Do because I don´t have the Cellnames at
> > this moment. I realized that I could get the edited Text with the
> > args.NewText property and the Rownumber with the args.Path Property, but
> > I can't see how to get the Fieldname. 
> >
> > Here is the Code that nakes me the treeview:
> >
> > --------------------------------------------------------------
> > public void DisplayDataGrid(Gtk.TreeView  treeview, ListStore store,
> > IDataReader reader)
> > {
> > int Index;
> > string FieldName;
> > int ColumnTotal;	
> > 		
> > ColumnTotal = treeview.Columns.Length;
> > for (Index = 0; Index < ColumnTotal; Index++)  //remove existing columns
> > {
> > Console.WriteLine("disposed: Column " + treeview.Columns[0].Title);
> >
> > treeview.Columns[0].Dispose();
> > treeview.Columns[0] = null;
> > treeview.RemoveColumn(treeview.Columns[0]);
> > }
> > 		
> > if (store != null)
> > {
> > store.Dispose();
> > store = null;
> > 			
> > Console.WriteLine("disposed: store");
> > }		
> >
> >
> > TreeViewColumn tvcol = new TreeViewColumn();  
> > CellRendererText tcellr = new CellRendererText();
> > tcellr.BackgroundGdk =  new Gdk.Color(220,220,220); 
> > tvcol.Title = "";	
> > tvcol.PackStart(tcellr, true); 
> > tvcol.AddAttribute(tcellr, "text", 0);
> > treeview.AppendColumn(tvcol); 
> > 			
> > for (Index = 0; Index < reader.FieldCount; Index++) //iterate through
> > each field of the database
> > {
> > FieldName = reader.GetName(Index); //get the query results field names
> > defined under strSQL
> > 				
> > TreeViewColumn col = new TreeViewColumn();  // add columns for each
> > field
> > CellRendererText colr = new CellRendererText();
> > colr.Editable = true; //Make every single Cell editable
> > colr.Edited += CellEdit;
> > 				
> > col.Title = FieldName;  //title the column with the field names
> > retrieved by the query
> > col.PackStart(colr, true);
> > col.AddAttribute(colr, "text", Index+1);
> > treeview.AppendColumn(col); //Add the Column to the Treeview
> > }
> > 			
> > //create array of strings one for each column
> > System.Type[] Fields = new System.Type[treeview.Columns.Length]; 
> >
> > for (Index = 0; Index < treeview.Columns.Length; Index++)
> > {
> > Fields[Index] = typeof(string); //set each type to string
> > }
> > 			
> > //The ListStore is a columned list data structure to be used with
> > TreeView widget. 
> > store = new ListStore(Fields);  //initialise store with columns
> > treeview.Model = store; //setup treeview with store
> > //The TreeIter is the primary structure for accessing a tree row
> > TreeIter iter = new TreeIter();
> > //add the data from the query to the treeview
> > string[] FieldArray = new string[treeview.Columns.Length];
> > int RowCount = 0;
> > while(reader.Read()) //read through reach row in result set returned by
> > the query 
> > {
> > RowCount += 1;
> > FieldArray[0] = RowCount.ToString(); //first column displays the row
> > count
> > 				
> > for (Index = 1; Index < treeview.Columns.Length; Index++)
> > {
> > FieldArray[Index] = reader.GetString(Index-1); //get the data from the
> > result set
> > FieldArray[Index] = FieldArray[Index].Trim();
> > 				}			
> > iter = store.AppendValues(FieldArray); //add row to treeview
> > }
> >   
> Hi, i'm not a guru in gtk# but i try to give some help.
> as far as i know if you want to update your tree "on the fly" all you 
> need to do is to call for a query to your sqlite DB with an edit 
> statement WHERE columnnale = valuebeforeedit
> once the "edited" method is invoked you do the query to your db...
> 
> 

Yes that is what I wanted to do. The Problem with this is that I don´t
have the columname in the edited method or I don´t know how to get it.
As I can see ther is no args Property that gives me the columname, only
Rownumvers and the edited Text.



More information about the Gtk-sharp-list mailing list