I have a small problem. I'm pretty much a newbie to C# coming out of VB.Net.
I have a windows form that has a GroupBox named grpSoldTo.
I want to be able to clear all the textboxes and comboxes that are in the GroupBox.
I know how to do it in VB.Net but when I try something similar in C# I get the following error:
Cannot implicitly convert type 'System.Windows .Forms.Control' to 'System.Windows .Forms.ComboBox '. An explicit conversion exists (are you missing a cast?)
Here is a snippet of my code:
The offending line is cmbo = ctrl;
Can anyone help?
Thanks,
Bill
I have a windows form that has a GroupBox named grpSoldTo.
I want to be able to clear all the textboxes and comboxes that are in the GroupBox.
I know how to do it in VB.Net but when I try something similar in C# I get the following error:
Cannot implicitly convert type 'System.Windows .Forms.Control' to 'System.Windows .Forms.ComboBox '. An explicit conversion exists (are you missing a cast?)
Here is a snippet of my code:
Code:
//Clear out the inputs
ComboBox cmbo = default(ComboBox);
foreach (Control ctrl in this.grpSoldTo.Controls)
{
if (ctrl.Name.StartsWith("txt"))
{
ctrl.Text = null;
}
else if (ctrl.Name.StartsWith("cmbo"))
{
cmbo = ctrl;
cmbo.SelectedIndex = 0;
}
}
Can anyone help?
Thanks,
Bill
Comment