Item collection cannot be modified when datasource property is set
-
Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks
-
Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks
when it is giving error? At the time of binding or at cother point. post code where it gives the error
himanshu
-
Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks
so, you can refared to below link: Add Item to Binded Combo Box[^] i founded my answer in this link
-
Hello.. Sir i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine.. gives an error......... Item collection cannot be modified when datasource property is set... Thanks
i sent full article of this code to CODEPROJECT . after that my article being accepted, you can use of them. but code is like this: you must use of NORTHWINFD Database
private void button1_Click(object sender, EventArgs e)
{
SqlConnection co = new SqlConnection();
co.ConnectionString = @"Server=.\SQLEXPRESS;initial catalog='NORTHWND.MDF';Trusted_Connection=Yes";
SqlCommand cmdSelect = new SqlCommand();
cmdSelect.Connection = co;
cmdSelect.CommandText = "SELECT (FirstName+' '+LastName) AS Fullname FROM Employees";
SqlDataAdapter da = new SqlDataAdapter(cmdSelect);
DataTable dt = new DataTable();
co.Open();
da.Fill(dt);
comboBox1.DataSource = null;
comboBox1.DataSource = dt;
comboBox1.ValueMember = "Fullname";
co.Close();
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)comboBox1.DataSource;
DataRow dr = dt.NewRow();
dr[0] = "< select item >";
dt.Rows.InsertAt(dr, 0);
comboBox1.DataSource = dt;comboBox1.SelectedIndex = 0; }