I suppose that your listboxes are defined in a Form (this). So you can simply get all the listboxes from the Controls collection with this line and add them with AddRange
listOfListBoxes.AddRange(this.Controls.OfType<ListBox>());
The Controls collection contains all the controls of your form defined at design time and created with the InitializeComponent call. This collection could be used in a loop and checked for every element if it is a ListBox with something like this code
foreach(Control c in this.Controls)
{
ListBox lb = c as ListBox;
if(lb != null)
listOfListBoxes.Add(lb);
}
but the introduction of the IEnumerable extensions in the namespace Linq has given the opportunity to avoid the explicit loop above and use the extension OfType that does the loop internally and yields each element of the type requested.
Finally you could add all these elements returned by OfType as an array to List.AddRange method
ListBox'sdefined at or coming from? Have you tried aforif so what is the issue?for (int i = 0; i < Controls.Count; i++) { if (Controls[i] is ListBox) listOfListBoxes.Add(Controls[i] as ListBox); }(Controls[i] is ListBox lBox)... then just add thelBoxto the list...