0

I am experiencing a problem where I have a button to populates a FlowLayoutPanel. All works well, and the combobox is generated. However, there is a small bug in the data populating of the combobox. I have a Binding source set up from my database and I link to the combobox in the following manner. The data is populated as expected, however, when I create another combobox using the same button, it always fills it with the same selection of data as the combobox above or below. The bizarre occurrence also happens when I have many more comboboxes. Here is my code. Any suggestions?

    private void additionalpartbtn_Click(object sender, EventArgs e)
    {
        string fieldname = "addpart";
        int fieldnamecount = 0;
        ComboBox newcombobox = new ComboBox();
        newcombobox.Name = fieldname + fieldnamecount;
        newcombobox.DataSource = sqlpartBindingSource;
        newcombobox.DisplayMember = "part";
        additionalpartspnl.Controls.Add(newcombobox);
        ComboBox newsidecombobox = new ComboBox();
        newsidecombobox.Name = "side" + fieldname + fieldnamecount;
        newsidecombobox.DataSource = sqlsideBindingSource;
        newsidecombobox.DisplayMember = "side";
        newsidecombobox.Size = new System.Drawing.Size(40, 21);
        additionalpartspnl.Controls.Add(newsidecombobox);
        fieldnamecount++;
    }
Jason Watkins
  • 3,766
  • 1
  • 25
  • 39
user3811284
  • 123
  • 2
  • 7
  • It look like sqlpartBindingSource and sqlsideBindingSource are not updated before you create a new control, so they are getting the same values. Are you updating them somewhere else before creating the control? –  Mar 31 '16 at 20:43
  • what is the purpose of it >>> int fieldnamecount = 0; – bluetoothfx Mar 31 '16 at 22:29
  • @bluetoothfx so the Comboboxes are named addpart1, addpart2, addpart3 – user3811284 Apr 01 '16 at 01:18
  • @RudyTheHunter no, I don't think I am updating them anywhere... How would I go about updating them? – user3811284 Apr 01 '16 at 01:19

0 Answers0