I have a ComboBox
dropdown to call it in some way ( System.Windows.Forms.ComboBox
) in which, I simply invoke the class method to load the data of the bd, the thing is that I have to add a field so that show me all the options that the drop-down has. And I do not know how to do it.
public FormSumatorio()
{
InitializeComponent();
List<Tienda> t_list = Tiendas.getTiendas();
foreach (Tienda t in t_list)
{
cBTiendas1.Items.Add(t);
}
cBTiendas1.SelectedIndex = 0;
//cBUnidades.SelectedIndex = 1;
}
GetTiendas Method:
public static List<Tienda> getTiendas()
{
List<Tienda> tiendas = new List<Tienda>();
string sql = "SELECT * FROM tiendas ";
MySqlCommand cmd = new MySqlCommand(sql);
MySqlDataReader reader = QueryPSDatabase(cmd);
if (reader.HasRows)
{
while (reader.Read())
{
Tienda t = new Tienda();
t.id_store = reader.GetString("id_store");
t.ref_tienda = reader.GetString("ref_tienda");
t.id_country = reader.GetString("id_country");
t.id_state = reader.GetString("id_state");
t.name = reader.GetString("name");
t.address1 = reader.GetString("address1");
t.address2 = reader.GetString("address2");
t.city = reader.GetString("city");
t.postcode = reader.GetString("postcode");
t.transportista = reader.GetString("id_transportista");
tiendas.Add(t);
}
}
reader.Close();
reader.Dispose();
return tiendas;
}
After obtaining all the stores, I call the method by clicking the button, in which I pass the argument of the store and I do another query to the bd to obtain all shipments according to the store, with which I would like to have a option that was to see everything. Obviously this list is included in a datagrid.
And the method that loads the info in the ComboBox
simply makes the query to mysql and I put everything in a list to send it to the form. With which I wanted to know how I could add an option manually (already with the query I have no problem)
Thanks in advance and regards.