ok, i tried your suggestion and I am getting a runtime error ...
An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll
Additional information: Error creating window handle.
Here is the code that I am using:
Private Sub frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'main sub is used to initialize database connections and form objects
main()
addControls() 'add dynamic form controls
end sub
Private Sub addControls()
.....database connection code ....
Dim i As Integer = 1
'add a row of controls for each record
Do Until objRs.EOF
''''lbl = New Label()
''''cbo = New ComboBox()
''''textFirst = New TextBox()
''''textLast = New TextBox()
ReDim Preserve lbl(i)
ReDim Preserve cbo(i)
ReDim Preserve textFirst(i)
ReDim Preserve textLast(i)
With lbl(i)
.Text = objRs.Fields("TeamName").Value
.Location = New Point(8, 104 + i * 40)
'.Size = New Size(100, 50)
.Name = lbl(i).ToString
End With
With cbo(i)
.Items.AddRange(New Object() {"Active", "Bye"})
.Text = "Active"
.Location = New Point(112, 96 + i * 40)
.Size = New System.Drawing.Size(121, 29)
AddHandler .SelectedValueChanged, AddressOf handlercboclick
.Name = cbo(i).ToString
End With
With textFirst(i)
.Location = New System.Drawing.Point(248, 96 + i * 40)
.Text = ""
.Name = textFirst(i).ToString
End With
With textLast(i)
.Location = New System.Drawing.Point(368, 96 + i * 40)
.Text = ""
.Name = textLast(i).ToString
End With
Controls.Add(lbl(i))
Controls.Add(cbo(i))
Controls.Add(textFirst(i))
Controls.Add(textLast(i))
objRs.MoveNext()
i = i + 1
Loop
End Sub
any suggestions on how to make this work would be greatly appreciated.
Thanks.