I have a datagridview
which is filled with this.adapter.Fill(this.addressesDataSet);
. In the grid, one column is combobox
which should display a list of cities for a given address.
The database contains data:
Partner_Address
id | address| city_id | ....
----------------------------------------
1 | asd | 5 |
City
id | City |
------------------
1 | New York |
2 | London |
The city_id column contains the foreign key id that is returned to the grid.
The problem is how to select a specific item in the combobox to display the name of the city for a specific row from the database. The database only returns the ID from the city but not the name.
I initialize grid with this
public void InitializePartnerAddressesList(int id)
{
using (this.conn = new MySqlConnection(DB.connString))
{
try
{
conn.Open();
string sql = "SELECT p.* FROM partneri_adrese p WHERE p.partner_id = @id and p.primarna";
this.adreseAdapter = new MySqlDataAdapter(sql, conn);
this.adreseAdapter.SelectCommand.Parameters.AddWithValue("id", id);
this.adreseAdapter.Fill(this.adreseDataSet);
this.adreseDataGridView.AutoGenerateColumns = false;
this.adreseBindingSource.DataSource = this.adreseDataSet.Tables[0];
this.adresBindingNavigator1.BindingSource = this.adreseBindingSource;
this.adreseDataGridView.DataSource = this.adreseBindingSource;
}
catch(Exception e) {
MessageBox.Show(e.Message);
}
}
}
When i run i get
Is this possible using an adapter or do I have to manually loop through each line and check it manually?