Please, read this:
WinForms get all controls of a specific type VB.NET - TechNet Articles - United States (English) - TechNet Wiki[
^]
Imports System.Windows.Forms
Public Module ControlExtensions
<Runtime.CompilerServices.Extension>
Public Function TextBoxList(pControl As Control) As List(Of TextBox)
Return pControl.Descendants(Of TextBox)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function LabelList(pControl As Control) As List(Of Label)
Return pControl.Descendants(Of Label)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function CheckBoxList(pControl As Control) As List(Of CheckBox)
Return pControl.Descendants(Of CheckBox)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function DataGridViewList(pControl As Control) As List(Of DataGridView)
Return pControl.Descendants(Of DataGridView)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function ComboBoxList(pControl As Control) As List(Of ComboBox)
Return pControl.Descendants(Of ComboBox)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function ListBoxList(pControl As Control) As List(Of ListBox)
Return pControl.Descendants(Of ListBox)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function DateTimePickerList(pControl As Control) As List(Of DateTimePicker)
Return pControl.Descendants(Of DateTimePicker)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function PictureBoxList(pControl As Control) As List(Of PictureBox)
Return pControl.Descendants(Of PictureBox)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function PanelList(pControl As Control) As List(Of Panel)
Return pControl.Descendants(Of Panel)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function GroupBoxList(pControl As Control) As List(Of GroupBox)
Return pControl.Descendants(Of GroupBox)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function ListViewList(pControl As Control) As List(Of ListView)
Return pControl.Descendants(Of ListView)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function ButtonList(pControl As Control) As List(Of Button)
Return pControl.Descendants(Of Button)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function RadioButtonList(pControl As Control) As List(Of RadioButton)
Return pControl.Descendants(Of RadioButton)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function RadioButtonChecked(pControl As Control, Optional pChecked As Boolean = True) As RadioButton
Return pControl.Descendants(Of RadioButton)().ToList().FirstOrDefault(Function(radioButton) radioButton.Checked = pChecked)
End Function
<Runtime.CompilerServices.Extension>
Public Function NumericUpDownList(pControl As Control) As List(Of NumericUpDown)
Return pControl.Descendants(Of NumericUpDown)().ToList()
End Function
<Runtime.CompilerServices.Extension>
Public Function ControlNames(pControls As IEnumerable(Of Control)) As String()
Return pControls.Select(Function(c) c.Name).ToArray()
End Function
<Runtime.CompilerServices.Extension>
Public Function IsContainer(pControl As Control) As Boolean
Return pControl.HasChildren
End Function
End Module
Here you'll find very interesting function, which gets all controls of specifi type:
vb.net - Enumerate all controls in a form (redundant) - Stack Overflow[
^]
Enum SearchMethod
StartsWith = 1
EndsWith = 2
Contains = 3
End Enum
Function GetAllControls(Of T As Control)(ctrl As Control, key As String, method As SearchMethod, Optional useTag As Boolean = True) As IEnumerable(Of T)
Dim upperKey = key.ToUpper
Dim searchPredicates() As Func(Of String, Boolean) = {
Function(src, tgt) src.StartsWith(upperKey),
Function(src, tgt) src.EndsWith(upperKey),
Function(src, tgt) src.Contains(upperKey)
}
Dim ctrlSelector As Func(Of Control, String) = If(useTag, Function(c) c.Tag.ToString.ToUpper, Function(c) c.Name.ToUpper)
Return GetAllControlsIterator(Of T)(ctrl, ctrlSelector, searchPredicates(CInt(method) - 1))
End Function
Private Iterator Function GetAllControlsIterator(Of T As Control)(ctrl As Control, ctrlSelector As Func(Of Control, String), searchPredicate As Func(Of String, Boolean)) As IEnumerable(Of T)
For Each child In ctrl.Controls
If searchPredicate(ctrlSelector(child)) AndAlso TypeOf child Is T Then Yield DirectCast(child, T)
For Each grandChild In GetAllControlsIterator(Of T)(child, ctrlSelector, searchPredicate)
Yield DirectCast(grandChild, T)
Next
Next
End Function
Good luck!