I am trying to read a combobox.Text from a thread other than the thread it was created on but I am getting the error:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control 'levelsComboBox' accessed from a thread other than the thread it was created on.
I have used .Invoke before but only to set properties, how can I use it to read combobox.Text? Because .Invoke returns void and I need a string. Or is there another way to do it without the Invoke?
By default, DropDownStyle property of a Combobox is DropDown. In this case user can enter values to combobox. When you change the DropDownStyle property to DropDownList, the Combobox will become read only and user can not enter values to combobox.
To remove an itemCall the Remove or RemoveAt method to delete items. Remove has one argument that specifies the item to remove. RemoveAt removes the item with the specified index number.
You can do it like this:
this.Invoke((MethodInvoker)delegate() { text = combobox.Text; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With