المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : how to fill a combobox with a class



C# Programming
04-28-2011, 06:23 PM
Hi,

I am filling a combobox with the code below:

private void frmCrearCooperativa_Load(object sender, EventArgs e)
{
string nacionalidad = "select * from cs_nacionalidad";
try
{
//open connection
bdConex.OpenConnection();
//create command and assign the query and connection from the constructor
MySqlDataAdapter da = new MySqlDataAdapter(nacionalidad, bdConex.conn);
//create dataset
DataSet ds = new DataSet();
// filling dataset
da.Fill(ds, "cs_nacionalidad");
//dataset values
cboNacionalidad.DataSource = ds.Tables["cs_nacionalidad"];
cboNacionalidad.DisplayMember = "nm_nacionalidad";
cboNacionalidad.ValueMember = "cd_nacionalidad";
//close connection
bdConex.CloseConnection();
}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

how do I can do a class that fills the combobox with this code?
because I have to write it down in all forms.

thanks.