S
shapper
Hello,
I am creating a custom control, named Form, which inherits from
CompositeControl.
I am adding child custom controls, named Section, to the Form through
the following property:
Private _Sections As New List(Of FormSection)
Public Property Sections() As List(Of FormSection)
Get
If _Sections Is Nothing Then
_Sections = New List(Of FormSection)
End If
Return _Sections
End Get
Set(ByVal value As List(Of FormSection))
_Sections = value
End Set
End Property ' Sections
Then I build my control as follows:
Protected Overrides Sub CreateChildControls()
For Each section As FormSection In Me.Sections
MyBase.Controls.Add(section)
Next ' section
MyBase.CreateChildControls()
End Sub
However, in OnBubbleEvent, which I am overriding, Me.Sections count 0
while Me.Controls count 4, the number of controls I added:
Protected Overrides Function OnBubbleEvent(ByVal source As Object,
ByVal e As EventArgs) As Boolean
Dim c As ControlCollection = Me.Controls
Dim s As List(Of FormSection) = Me.Sections
End sub
Why?
I was using a Loop with Me.Sections and it was not working and now I
found out why.
What am I doing wrong?
Thanks,
Miguel
I am creating a custom control, named Form, which inherits from
CompositeControl.
I am adding child custom controls, named Section, to the Form through
the following property:
Private _Sections As New List(Of FormSection)
Public Property Sections() As List(Of FormSection)
Get
If _Sections Is Nothing Then
_Sections = New List(Of FormSection)
End If
Return _Sections
End Get
Set(ByVal value As List(Of FormSection))
_Sections = value
End Set
End Property ' Sections
Then I build my control as follows:
Protected Overrides Sub CreateChildControls()
For Each section As FormSection In Me.Sections
MyBase.Controls.Add(section)
Next ' section
MyBase.CreateChildControls()
End Sub
However, in OnBubbleEvent, which I am overriding, Me.Sections count 0
while Me.Controls count 4, the number of controls I added:
Protected Overrides Function OnBubbleEvent(ByVal source As Object,
ByVal e As EventArgs) As Boolean
Dim c As ControlCollection = Me.Controls
Dim s As List(Of FormSection) = Me.Sections
End sub
Why?
I was using a Loop with Me.Sections and it was not working and now I
found out why.
What am I doing wrong?
Thanks,
Miguel