[Gtk-sharp-list] Dynamic from SQLite popuplated Treeview mad editable
Sebastian
exit at are-you-ready.de
Mon Aug 30 02:39:16 EDT 2010
Am Donnerstag, den 26.08.2010, 08:45 -0400 schrieb Adam Tauno Williams:
> 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.
I realised that I sended my answer not to the List but to awilliams himself. Here is a copy for the list:
----------------------------------------------------------------------------------------------------------
Really nice try. That looks like very clean Code. I tried it but got the
error that Mono expects a string or base in the Brackets here:
public BoundCellRendererText(string _fieldName) : CellRendererText()
Couldn't get it to work. Could you tell me waht am I doing wrong?
More information about the Gtk-sharp-list
mailing list