动态添加复选框到组框

时间:2014-02-27 18:27:43

标签: vb.net checkbox groupbox

我正在尝试根据数据表中的行数动态地将复选框添加到分组框中。当循环通过我得到我的第一个结果,但我无法得到下一个结果显示...这是我的代码

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

1 个答案:

答案 0 :(得分:1)

所有控件都直接在彼此之上:

checkgross.Location = New Point(40, checkHG + 20)

由于checkHG永远不会改变。更改每个动态控件的位置()...