Language: C#
Get all controls of a type from a form / container
// 3.5: var radioGroups = this.Controls.OfType<RadioGroup>().ToList(); // old way using recursion: var radioGroups = GetAllRadioGroups(this.Controls); /// <summary> /// Return a list of radiogroup controls within the current controls collection, recursively /// </summary> /// <param name="controls"></param> /// <returns></returns> public static List<RadioGroup> GetAllRadioGroups(this Control.ControlCollection controls) { List<RadioGroup> list = new List<RadioGroup>(); foreach (Control control in controls) { if (control is RadioGroup) { list.Add(control as RadioGroup); } else if (control.HasChildren) { list.AddRange(control.Controls.GetAllRadioGroups()); } } return list; } // Using the list radioGroups.ForEach(control => control.ItemNotInList += new UltraComboEditor.ItemNotInListEventHandler(InfragisticsHelper.UltraComboEditor_ValidateItemInList));
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

