0
votes

enter image description here

In brief: I want to load my form, then using a Background Worker fetch data from Database and set the DataSource of some comboboxes.
In DoWork event I fetch data, and in RunWorkerCompleted event I set the datasources. The problem is cross-threading issues. What can I do to resolve this?

I don't understand why setting DisplayMember is OK but in next line, setting ValueMember throws an exception

2
Please post the code not a picture of it. - Richard Schneider
sorry @RichardSchneider, thanks for mentioning - Mahdi Tahsildari

2 Answers

11
votes

You can use the control's 'Invoke' method to run code in the same context(thread) as that control. Here is a simple example:

comboBox1.Invoke((MethodInvoker)delegate{
       //Code to modify control will go here
            comboBox1.Text = "";
        });   
2
votes

I think you got it backwards. The DoWork should be FetchData and DoWorkCompleted should be BindComboBoxes.