为数据库中的一行创建动态控件

时间:2015-11-30 18:53:25

标签: vb.net winforms dynamic

我需要能够为dataTable中的每一行创建动态单选按钮和标签。到目前为止我写的代码生成了链接的单选按钮,所以我一次选择多个按钮。相反,单选按钮在按下另一个按钮时取消选择。

Do
        For count = 0 To NoOfRecords - 1
            For i = 1 To NoOfRecords - 1
                Dim XCoord, YCoord As Integer
                XCoord = 269
                YCoord = 172

                Dim XCoord1, YCoord1 As Integer
                Dim Labeli As Label
                Dim RadioButtonsi As RadioButton
                XCoord1 = 269 : YCoord1 = 172

                For count1 = 0 To NoOfRecords - 1
                    Labeli = New Label
                    Labeli.Location = New System.Drawing.Point(XCoord, YCoord)
                    YCoord = YCoord + 120
                    Labeli.Text = count1 & ". " & dataTable.Rows(count1).Item(0)
                    Me.Controls.Add(Labeli)

                    RadioButtonsi = New RadioButton
                    RadioButtonsi.Location = New System.Drawing.Point(XCoord1, (YCoord1 + 20))
                    YCoord1 = YCoord1 + 120
                    RadioButtonsi.Text = dataTable.Rows(count1).Item(1)
                    Me.Controls.Add(RadioButtonsi)
                Next
            Next
        Next
    Loop Until count = NoOfRecords

总而言之,我需要能够为dataTable中未链接的每一行创建控件。

0 个答案:

没有答案