I was playing around, trying to see if you could change a bunch of labels in a container, and came up with the following code :
I tried running the code, but it threw an exception at :
"Dim control As ControlCollection = Me.Panel1.Controls"
saying :
"Unable to cast object of type 'ControlCollection' to type 'ControlCollection'"
Anyone able to explain what's going on here? Incidently, it works if I don't use the container.
VB.NET:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles Button1.Click
Dim control As ControlCollection = Me.Panel1.Controls
For Each lbl As Object In control
lbl.Text = "hi"
Next
End Sub
End Class
I tried running the code, but it threw an exception at :
"Dim control As ControlCollection = Me.Panel1.Controls"
saying :
"Unable to cast object of type 'ControlCollection' to type 'ControlCollection'"
Anyone able to explain what's going on here? Incidently, it works if I don't use the container.