I'm making the combobox which contains list of added Home adresses from DB, I'm trying to implement the option to change the text of what the current adress is called in combobox. For examples its now adressID fetched from db, but I'd like to add a option to call it for example "Adress 1" instead of just adressID.. I've tried some options from before suggested examples from google, but I get this error: Items collection cannot be modified when the DataSource property is set. because im using datasource. Anyone have an idea on how could this be fixed?
This is my code:
private void getAdr()
{
string connStr = "Data Source=MARINCHI\\SQLEXPRESS;Initial Catalog=login1;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand getAdr = new SqlCommand("SELECT adressID, userID, adress, floor,city, state, country, zipcode FROM userAdress where userID = @userID", conn);
SqlParameter parUserID = new SqlParameter("@userID", Login.id);
getAdr.Parameters.Add(parUserID);
getAdr.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(getAdr);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "adressID";
comboBox1.ValueMember = "adressID";
textBox5.DataBindings.Add("Text", dt, "adress");
textBox6.DataBindings.Add("Text", dt, "floor");
textBox7.DataBindings.Add("Text", dt, "city");
textBox8.DataBindings.Add("Text", dt, "state");
textBox9.DataBindings.Add("Text", dt, "country");
textBox10.DataBindings.Add("Text", dt, "zipcode");
comboBox1.Items[comboBox1.SelectedIndex] = "Adress 1";
}