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

Adam Tauno Williams awilliam at whitemice.org
Thu Aug 26 08:45:05 EDT 2010


On Thu, 2010-08-26 at 12:25 +0200, Sebastian wrote:
> 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
> 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.AddAttribute(colr, "text", Index+1);
> treeview.AppendColumn(col); //Add the Column to the Treeview
> }

Why not
 
public class BoundCellRendererText : CellRendererText
{
   string fieldName;

   public BoundCellRendererText(string _fieldName) : CellRendererText()
   {
      this.fieldName = _fieldName
   }

   public string FieldName { get { return this.fieldName; } }
}

And use that in place of CellRendererText.
BoundCellRendererText colr = new BoundCellRendererText(fieldname);
colr.Editable = true; //Make every single Cell editable
colr.Edited += CellEdit;
...
treeview.AppendColumn(col); //Add the Column to the Treeview

And then in the EditedHandler your "o" would be your
BoundCellRendererText that knows about the field name.
-- 
Adam Tauno Williams <awilliam at whitemice.org> LPIC-1, Novell CLA
<http://www.whitemiceconsulting.com>
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba



More information about the Gtk-sharp-list mailing list