Since you are using C # 2.0, you are pretty much out of luck. You can write the function yourself. In C # 3.0, you simply do:
foreach (var control in groupBox.Controls.OfType<ComboBox>()) {
C # 2.0 solution:
public static IEnumerable<T> GetControlsOfType<T>(ControlCollection controls) where T : Control { foreach(Control c in controls) if (c is T) yield return (T)c; }
which you would use for example:
foreach (ComboBox c in GetControlsOfType<ComboBox>(groupBox.Controls)) {
source share