Populating a Winforms ComboBox with Csharp
-10
Example that shows how to populate a winforms combobox with csharp. It uses Data Access blocks (SqlHelper).
private void PoblarComboPais()
{
// Trae las sociedades correspondientes al paƬs
Cursor.Current = Cursors.WaitCursor;
// Conexion
string cn = SqlOptions.ConnectionString();
// DataReader
this.cboPais.DataSource = SqlHelper.ExecuteDataset(cn,CommandType.Text , "SELECT * FROM MAE_PAIS").Tables[0];
this.cboPais.ValueMember = "chrPais";
this.cboPais.DisplayMember = "chrPaisNombre";
//Puntero del mouse normal
Cursor.Current = Cursors.Default;
}






Aggghhhh my eyes are bleeding!
I mean sure, this is fine for a tiny util, but any slightly larger program will buckle under the inflexibility of this code.
I would recommend giving the form a public method for passing in a datatable and then pass that table in from a controller object that both speaks to the form and speaks to the database.