[RESOLVED] How to make a Collection from a list of UserControlls to call in For-Each?
If their number is specific we would do this
Code:
Dim UC As UserControl1() = {UserControl11, UserControl12, UserControl13, UserControl14}
For i As Integer = 1 To 4
UC(i - 1).Enabled = True
Next
And do some stuffs on all of them at once.
Now let's suppose UserControl1 would be added programmatically in a various uncertain number each time. Plus there is "For Each" sort of loop which could be make it easier. How can we use it? A proper way. How can we perform a similar thing here?
Note:
They're added in TableLayoutPanel if it helps.
Re: How to make a Collection from a list of UserControlls to call in For-Each?
vb.net Code:
Dim userControls = myTableLayoutPanel.Controls.OfType(Of UserControl1)().ToArray()
If you're going to use a For Each loop then you don;t even need the array. You can enumerate the result of OfType directly:
vb.net Code:
For Each uc1 In myTableLayoutPanel.Controls.OfType(Of UserControl1)()
Re: How to make a Collection from a list of UserControlls to call in For-Each?
Quote:
Originally Posted by
jmcilhinney
vb.net Code:
For Each uc1 In myTableLayoutPanel.Controls.OfType(Of UserControl1)()
Fantastic! That's what I was looking for... Thanks.