I'm dynamically creating controls and inserting them into a Panel. My problem is that I'm creating a Checkbox control (setting various properties) and then a Label control (setting various properties). I wish for the text for each of the controls to be Black and Red respectively. They are to be right beside each other with a blank space separating them. The code I have provided does this if the for loop contains 1 iteration. If their are more than 1 iteration, the Red Asterisk doesn't show up. I've tried adding spaces between each occurrence of the checkbox and it still won't show up. Anyway, here is my code:
Code:
            If resp Is Nothing Then
                Dim asterisk As New Label
                asterisk.Text = "*"
                For Each row As DataRow In ds2.Tables(0).Rows
                    Dim chk As New CheckBox
                    chk.AutoSize = True
                    chk.Top = 7
                    chk.BackColor = pnl1.BackColor
                    chk.ForeColor = Color.Black
                    chk.TextAlign = ContentAlignment.MiddleLeft
                    chk.Text = row("labelName")
                    chk.Left = tmpWidth
                    Me.pnl2.Controls.Add(chk)
                    If row("required") = "Y" Then
                        asterisk.Top = chk.Top
                        asterisk.Left = chk.Width
                        asterisk.ForeColor = Color.Red
                        Me.pnl2.Controls.Add(asterisk)
                        tmpWidth = tmpWidth + chk.Width + 25
                    Else
                        tmpWidth = tmpWidth + chk.Width
                    End If
                    AddHandler chk.Click, AddressOf CheckBox1_Click
                Next
           End If