0
我想動態地添加複選框到基於數據表中的行數的組框。循環時通過我得到我的第一個結果,但我沒能獲得下結果顯示...這裏是我的代碼動態添加複選框到組框
Dim q As String
Dim qt As DataTable
Dim gbHeight As Integer = 40
Dim checkHG As Integer = 5
Dim checkHN As Integer = 5
q = "Select * from loads where filenumber = " & Shipments2.txtFileNumber.Text
qt = GetSQL(q)
For i = 0 To qt.Rows.Count - 1
Dim items As New List(Of LoadDetails)
Dim ld As New LoadDetails
items = ld.GetListBySQL("select * from loadDetails where LoadNumber = " & qt.Rows(i).Item("id"))
For Each item As LoadDetails In items
Dim checkgross = New CheckBox
Dim checknet = New CheckBox
gbHeight += 20
'add checkbox control to form
checkgross.Location = New Point(40, checkHG + 20)
checkgross.Text = item.Description & " (Gross)"
checkgross.Size = New Size(250, 20)
checkgross.Name = item.ProductCode.ToString & "-gross"
gbGross.Size = New Size(329, gbHeight)
gbGross.Controls.Add(checkgross)
rbPrintingNet.Location = New Point(rbPrintingNet.Location.X, rbPrintingNet.Location.Y + 40)
checknet.Location = New Point(40, checkHN + 20)
checknet.Text = item.Description & " (Net)"
checknet.Size = New Size(250, 20)
checknet.Name = item.ProductCode.ToString & "-net"
gbNet.Location = New Point(44, rbPrintingNet.Location.Y + 25)
gbNet.Size = New Size(329, gbHeight)
gbNet.Controls.Add(checknet)
Me.Size = New Size(Me.Size.Width, Me.Size.Height + 50)
Next
Next
工作正常!感謝百萬Idle_mind! – popojohn
您可以在GroupBox中添加一個停靠的** FlowLayoutPanel **,以便您不必擔心顯式設置每個動態控件的Location()。 –