title: Setting ComboBox DataSource from backgroundWorker in C#
body: <p>I have a problem with populating my comboBoxes in a WinForm application that I'm writing. The data that I use to populate these comboBoxes is pulled from database. The problem is that there is a lot of data that needs to be binded to the comboBoxes, so this process takes a very long time during which the entire application is locked (the entire process of binding data takes over 9 seconds, while the process of pulling the data from the database takes only 400 milliseconds). I'm trying to speed things up by splitting the processes of creating the controls (main thread) and populating the comboBoxes (background worker), but naturally I get the cross thread error. 
  This is the part of code that I use:</p>
  
  <pre><code>private void Populate()
      {                                  
          comboBox1.BindingContext = new System.Windows.Forms.BindingContext();
          comboBox1.DataSource = MyClass.dtMyDataTable;
          comboBox1.DisplayMember = "TitleColumn";
  
          .//I repeat the same code for each comboBox
          .//I use the BiningContext because some of the comboBoxes have to display the 
          .//same data.            
      }
  </code></pre>
  
  <p>I created a class that contains all DataTables that I need in this form - there are multiple forms that use the same data from the database, so I created a class and created an object that fills all of these DataTables on the parent Form.Load(), and then I pass them to the children forms when I create them. This way I load the data when the application loads (it doesen't even take that long), so it should be ready to use when I call it from child forms. I've tried to call the <code>Populate()</code> method from <code>backgroundWorker.DoWork()</code> method, and there I get the cross thread error.</p>
  
  <p>My question is - is there a way to make this work, and if not, what could I use as alternative solution.</p>
  
  <p>Thank you</p>