In my code I need to loop through the controls in a GroupBox and process the control only if it a ComboBox. I am using the code:
foreach (System.Windows.Forms.Control grpbxChild in this.gpbx.Controls)
{
if (grpbxChild.GetType().Name.Trim() == "ComboBox")
{
// Process here
}
}
My question is: Instead of looping through all the controls and processing only the combo boxes is is possible to get only the combo boxes from the GroupBox? Something like this:
foreach (System.Windows.Forms.Control grpbxChild in this.gpbx.Controls.GetControlsOfType(ComboBox))
{
// Process here
}
Since you are using C# 2.0, you’re pretty much out of luck. You could write a function yourself. In C# 3.0 you’d just do:
C# 2.0 solution:
which you’d use like: