In your example your ctl
variable is a Control
and not a Combobox
so it does not have the SelectIndex
property - though you could have casted it back with DirectCast(ctl, Combobox)
.
For Each ctl As Control In (GroupBox1.Controls)
If TypeOf ctl Is Combobox Then
DirectCast(ctl, Combobox).SelectedIndex = -1
End If
Next
Or create a loop of type specific control for your loop. No need to check type here.
Dim cbs = GroupBox1.Controls.OfType(Of Combobox)()
For Each cb In cbs
cb.SelectedIndex = -1
Next
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…