Hello, I have a datagridview which has a combobox.
I want to populate this comboboxes at runtime. But I don't know how.
In the database I have:
Column1 : Name | Column2 : Quantity | Column 3 : Date |
a | 1 | 2019 |
b | 2 | 2018 |
c | 3 | 2017 |
a | 4 | 2015 |
So what I need is to show in my combobox for Name a : (1 - 2019) (4 - 2015)
These two must be filled in the combobox.
For Name b the combobox will be : (2 - 2018)
But what I get is that my combobox is filling all the data not only what I need
The code I tried:
- using (MySqlDataAdapter sda = new MySqlDataAdapter(@"SELECT DISTINCT Name ,CONCAT(Quantite ,'PCS -' ,Date) as Conc FROM articles", MyConnexion))
- {
- DataTable dt = new DataTable();
- sda.Fill(dt);
- DTG_Bordereau.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- DTG_Bordereau.Columns[0].DataPropertyName = "Name";
-
- DTG_Bordereau.Columns[3].Width = 300;
-
- DTG_Bordereau.DataSource = dt;
-
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- var val = dt.Rows[i]["Conc"].ToString();
-
-
- if (!QuantiteDisponible.Items.Contains(val))
- {
- QuantiteDisponible.Items.Add(val);
- }
-
- }