Hi people!

I am trying to develop a simple application that saves an Id and a
name, but I am having some difficulty with it, let's see the problem:

using System;
using Gtk;
using Npgsql;
using System.Data;
using ApplicationClientes;

namespace ApplicationClientes
{
        public class Clientes
        {
                public static void Main(string[] args)
                {
                        Application.Init();
                        ClientesGUI clientesGUI = new ClientesGUI();
                        clientesGUI.DeleteEvent += OnClientesGUIDelete;
                        clientesGUI.Show();
                        Application.Run();
                }
                public static void OnClientesGUIDelete(object sender, EventArgs 
args)
                {
                        Application.Quit();
                }
        }
        public class ClientesGUI: Window
        {
                ClientesDBL clientesDBL;
                DataSet ds;
                DataRow dr;
                TreeView tv;
                ListStore ls;
                TreeViewColumn tvcId;
                CellRendererText crtId;
                TreeViewColumn tvcNome;
                CellRendererText crtNome;
                public ClientesGUI(): base("Cadastro de clientes")
                {
                        clientesDBL = new ClientesDBL();
                        ds = clientesDBL.GetClientes();
                        this.SetDefaultSize(200, 200);
                        tv = new TreeView();
                        ls = new ListStore(typeof(string), typeof(string));

                        tvcId = new TreeViewColumn();
                        crtId = new CellRendererText();
                        crtId.Editable = true;
                        tvcId.Title = "Código";
                        tvcId.PackStart(crtId, true);
                        tvcId.AddAttribute(crtId, "text", 0);
                        tv.AppendColumn(tvcId);

                        tvcNome = new TreeViewColumn();
                        crtNome = new CellRendererText();
                        crtNome.Editable = true;
                        crtId.Edited += new EditedHandler(OnCtrNomeEdited);
                        tvcNome.Title = "Nome";
                        tvcNome.PackStart(crtNome, true);
                        tvcNome.AddAttribute(crtNome, "text", 1);
                        tv.AppendColumn(tvcNome);

                        tv.Model = ls;

                        for(int i = 0; i < ds.Tables["Clientes"].Rows.Count; 
i++)
                        {
                                dr = ds.Tables["Clientes"].Rows[i];
                                Console.WriteLine("{0} {1}", dr["cliId"], 
dr["cliNome"]);
                                
ls.AppendValues(dr["cliId"].ToString(),dr["cliNome"].ToString());
                        }

                        this.Add(tv);
                        this.ShowAll();
                }
                public void OnCtrNomeEdited(object sender, EditedArgs args)
                {
                        TreeIter iter;
                        if (ls.GetIter (out iter, new TreePath (args.Path)))
                        {
                                ls.SetValue (iter, 1, args.NewText;
                                ds.Tables["Clientes"].Rows[ /*HERE!, HOW TO 
OBTAIN THE ID OF THE
FIRST COLUMN?*/ ]["cliNome"] = args.NewText;
                        }
                }
        }
        public class ClientesDBL
        {
                NpgsqlConnection cn;
                NpgsqlDataAdapter da;
                NpgsqlCommandBuilder cb;
                DataSet ds;
                public ClientesDBL()
                {
                        cn = new 
NpgsqlConnection("Server=localhost;Port=5432;TimeOut=15;Database=adriano;User
ID=adriano;Password=cap2584;");
                        da = new NpgsqlDataAdapter("SELECT cliId, cliNome FROM 
clientes;", cn);
                        cb = new NpgsqlCommandBuilder(da);
                        ds = new DataSet();
                }
                public DataSet GetClientes()
                {
                        da.Fill(ds, "Clientes");
                        return ds;
                }
                public void SaveClientes(DataSet ds)
                {
                        da.Update(ds, "Clientes");
                }
        }
}

Compiling:

gmcs /r:/usr/lib/mono/2.0/Npgsql.dll
/r:/usr/lib/mono/gtk-sharp-2.0/gtk-sharp.dll /r:System.Data
Clientes.cs

The code above has a line with the text "/*HERE!, HOW TO OBTAIN THE ID
OF THE FIRST COLUMN?*/" where I would like to obtain the number of the
line in order to save the date back to the dataset and after closing
the form it would be saved with an update method of the dataadapter,
could someone point out the missing line?
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to