[Gtk-sharp-list] GTK# with a treeview: simple example

Daniel Dieterle daniel at dieterle.ws
Tue Mar 6 10:35:29 EST 2007


Hi everybody, 

i wrote a simple program in C#. I'm a beginner with C# and GTK#. 
The graphics i layouted with Glade. When i want to add a column, the
compiler complains always with a error. 
I found no information, how to add a column while the windows is with
Glade formatted and in C# written. 

My code is the following: 
------------------------------------------------------------------------------------------ 
using System; 
using Gtk; 
using Glade; 
using System.Security.Principal; // pour recuperer le nom d'utilisateur 

class BrowserWindow 
{ 
        [Widget] Gtk.TreeView treeview1; 

        Gtk.ListStore musicListStore = new Gtk.ListStore (typeof
(string), typeof (string)); 
        treeview1.AppendColumn ("Artist", new Gtk.CellRendererText (),
"text", 0); 
        treeview1.AppendColumn ("Title", new Gtk.CellRendererText (),
"text", 1); 

        musicListStore.AppendValues ("Garbage", "Dog New Tricks"); 
        treeview1.Model = musicListStore; 


        // boutton lire 
        void on_button1_clicked (object o, EventArgs e) 
        { 
        } 

        // boutton ecrire 
        void on_button2_clicked (object o, EventArgs e) 
        { 
        } 

        // boutton quitter 
        void on_button3_clicked (object o, EventArgs e) 
        { 
                Application.Quit (); 
                System.Environment.Exit (0); 
        } 

        // creer une fenetre comme d'ecrit avec le logiciel Glade 
        public BrowserWindow () 
        { 
                Glade.XML gui = new Glade.XML ("./browser.glade",
"window1", ""); 

                // connect les bouttons avec le fenetre(signal-handler) 
                gui.Autoconnect(this);

                    
  } 
} 

class BrowserDemo { 

        static void Main () { 
                // neccesary pour initialiser Gtk 
                Gtk.Application.Init(); 

                // creer un nouvelle fenetre 
                new BrowserWindow(); 


                // donne le nom d'utilisateur 
                string UserName =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); 
                Console.WriteLine(UserName); 

                // lance le fenetre 
                Gtk.Application.Run(); 
        } 
} 
--------------------------------------------------------------------------------------------------- 

Compiled with: 

vmware at vmware-bavm:~/progs/browser$ mcs browser.cs -pkg:gtk-sharp-2.0
-pkg:glade-sharp-2.0 
syntax error, got token `OPEN_PARENS' 
browser.cs(11) error CS8025: Parsing error 
Compilation failed: 1 error(s), 0 warnings 
vmware at vmware-bavm:~/progs/browser$ 

Any hints? 


Thanks indeed. 
Daniel. 






More information about the Gtk-sharp-list mailing list