I’m trying to populate combobox from listbox elements.
this is code:
foreach(string elements in (Application.OpenForms[1] as Impostazioni).listBox1)
{
cbxValuta.Items.Add(elements);
}
but I get this error from Visual Studio 2012:
Error 1 foreach statement cannot operate on variables of type
‘System.Windows.Forms.ListBox’ because ‘System.Windows.Forms.ListBox’
does not contain a public definition for ‘GetEnumerator’
I dont know how solve this error.
If you want iterate over ListBox elements you must use Items property.
Try this:
Error:
First of all you must check if Application.OpenForms is not null and not empty.
So before foreach you must add following line of code:
If Application.OpenForms is list:
If Application.OpenForms is array: