Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have an following issue.
Items collection cannot be modified when the DataSource property is set.
I am using Combobox in c#.net windows application.
at form load event following code.

setCombobox_LoadRecords("SELECT ProductName FROM Product_Info", "Product_Info", "ProductName", comboBoxPerticulars);

that calls method below.

C#
public static void setCombobox_LoadRecords(string SQL, string Table, string FieldName, ComboBox combo)
        {
            try
            {
                combo.Items.Clear();
                DataSet dataset = new DataSet();

                Adapter = new SqlDataAdapter();

                connection.setCommand(dataset, Adapter, SQL, Table);
                combo.DataSource = dataset.Tables[0].DefaultView;
                combo.DisplayMember = FieldName;
                combo.ValueMember = FieldName;
                combo.SelectedIndex = -1;

            }
            catch (Exception ex) { ex.ToString(); }
        }


so i want to show Select Text at index -1.
Please help me.
Posted
Updated 22-Feb-15 21:22pm
v2

1 solution

This is because when you connect it to the DataSource, the data source delivers the data. Adding custom data yourself would not work because then the component would have another DataSource, namely you. If you want to add data you should add it to the DataSource directly.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900