How can I add checkBox dinamically in a Form?

Joined
May 20, 2006
Messages
7
Programming Experience
Beginner
Hello!

I have an ArrayList of Strings. And I have to add one checkbox to every word contained in the ArrayList.

I try with this:

VB.NET:
        Dim startPositionInForm = 30
        For i = 0 To ArrayList.Count - 1
            Dim check As New System.Windows.Forms.CheckBox
            check.Location = New System.Drawing.Point(16, startPositionInForm + 20)
            check.Name = ArrayList.Item(i)
            check.Size = New System.Drawing.Size(94, 24)
            check.TabIndex = i
            check.Text = ArrayList.Item(i)
            check.Checked = True
            Controls.Add(check)
            startPositionInForm = startPositionInForm + 20
        Next
        Refresh()
But with this code, only the first check is showed. And I don't know why!
Thanks in advance
 
That code is fine, except ArrayList should be named something else than the class name ArrayList. If that code results in only one CheckBox, then there is only one string in ArrayList. Perhaps post more code?
 
Wow!

Thanks JohnH you were right!
I was blind and I was sure that this arraylist was full of Strings and the problem were that was with only one String!

Thanks a lot ;)
 
Back
Top