|
-
Aug 3rd, 2020, 12:41 PM
#1
Thread Starter
Lively Member
How do I create lots of controls faster in a dynamic form?
I am looping through a SQL database of about 15 to 30 records and creating a set of about 50 controls per record, then populating each control with the correlating data. These controls range from textboxes, comboboxes, buttons, rich text boxes, checkboxes, labels, etc.
However, this is taking very long to load and I cannot figure out a faster way to do this. Also, the application is locking up my computer when open.
Any tips or advice would greatly be appreciated.
Thanks in advance!
Example of how I am creating and populating a control: (In my actual code there are a lot more controls inside the For Each Loop in the example below)
Code:
'Fill Datatable with data from SQL
con.Open()
DT.Clear()
DTadapter = New SqlDataAdapter("SELECT * FROM TABLE", con)
DTdapter.Fill(DT)
Count = 0
'Loop through DataTable and create controls for each record
For Each row In DT.Rows
'-----------Company
Dim companyTB As New TextBox
companyTB.Name = "companyTB" & Count
With companyTB
.Size = New Size(200, 20)
companyTB.Font = New Font("Trebuchet MS", 9, FontStyle.Bold)
companyTB.BackColor = Color.LightYellow
If Count = 0 Then
.Location = New Point(10, 20)
Else
Y = Y + 460
.Location = New Point(10, Y)
End If
End With
'Add Control to Panel
QC_Panel.Controls.Add(companyTB)
'Populate Control with Data
companyTB.Text = DT.Rows(Count)("COMPANY NAME").ToString
Count = Count + 1
Next
Con.close()
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|