[Mono-list] FileChooserDialog

Paulo Augusto PauloMorfeo at portugalmail.pt
Sat Jan 14 12:47:02 EST 2006

I am trying to use FileChooserDialog but it is failing me. There isn't
much documentation about it and, so, i'm trying an example which is
mostly the same as the example of FileSelection which is in the
documentation and works fine.

using System;
using Gtk;

namespace Aprendizagem
	public class ExemploFileChooserDialog
		Label lbl;
		FileChooserDialog fc;
		public ExemploFileChooserDialog ()
			Application.Init ();
			Window win = new Window ("FileSelectionSample");
			win.SetDefaultSize (250,200);
			win.DeleteEvent += new DeleteEventHandler (Sair);
			VBox vbox = new VBox (true, 1);
			win.Add (vbox);
			Button btn = new Button ("Select a file.");
			btn.Clicked += new EventHandler (BtnClicked);
			vbox.Add (btn);
			lbl = new Label ("Selected: ");
			vbox.Add (lbl);
			win.ShowAll ();
			fc = new FileChooserDialog ("Choose a folder", win,
										FileChooserAction.SelectFolder, null);
			fc.Response += new ResponseHandler (OnFileSelectionResponse);
			Application.Run ();
		void BtnClicked (object o, EventArgs args)
		void OnFileSelectionResponse (object o, ResponseArgs args)
			if (args.ResponseId == ResponseType.Ok)
				lbl.Text = "Selected: " + fc.Filename + "\n" +
					"Folder: " + fc.CurrentFolder;
		void Sair (object o, DeleteEventArgs args)
			Application.Quit ();

When trying to run, the output is this:

Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
in <0x0019c> Gtk.FileChooserDialog:.ctor (System.String title,
Gtk.Window parent, FileChooserAction action, System.Object[]
in <0x0019a> Aprendizagem.ExemploFileChooserDialog:.ctor ()
in <0x00016> Aprendizagem.Program:Main (System.String[] args)

Anyone could help me out in what's wrong of if it is some bug!?

More information about the Mono-list mailing list