[Gtk-sharp-list] Is there an sample on how to fill a ComboBoxEntry with data from ADO.Net?

Madian madian001 at gmail.com
Thu Mar 5 11:52:58 EST 2009


I know it's to late but i hope this could help to oters users,
If you are tying to implement something like the datasource or datamember of
the 
windows forms controlls remember in GTK there is something called MVC(modell
view controller)
see: http://en.wikipedia.org/wiki/Model-view-controller

ok, so you can fill or get back data from a database whit this sub

We will supose that have a table whit tow fields(Id, Name)
//I don't now why but always the first column it must to be string,
//(if you want to enable the entrycompletion)
//and the type of the others columns it does not matter.

public static void FillCombo (ComboBoxEntry cbo,string qry)
{
	string error = "";
	
	MySqlCommand cmd = new MySqlCommand();
	MySqlDataReader dr;
	MySqlConnection cn = new MySqlConnection(strConnectionString);
	
	try{
		cn.Open();
		cmd.CommandText = qry;
		cmd.Connection = cn;
		dr = cmd.ExecuteReader();
		
		if (dr.HasRows)
		{
			ListStore store = new ListStore (typeof (string),typeof(int));
			while (dr.Read())
				store.AppendValues (dr.GetString(1),dr.GetInt32(0));
			
			cbo.Model = store;
			cbo.Entry.Completion = new EntryCompletion();
			cbo.Entry.Completion.Model = store;
			cbo.Entry.Completion.TextColumn = 0;
		}
		dr.Close();
	}catch(MySqlException ex){
		error = ex.Message+" "+ex.Number;
	}catch(Exception e){
		error = e.Message;
	}finally{
		cmd.Dispose();
		cmd.Connection.Dispose();
		
		if (error.Length>0)
			Console.WriteLine(error,MessageType.Error);
	}
}
Any doubt mail me please
-- 
View this message in context: http://www.nabble.com/Is-there-an-sample-on-how-to-fill-a-ComboBoxEntry-with-data-from-ADO.Net--tp3327597p22355672.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.



More information about the Gtk-sharp-list mailing list