如何使用GroupBox和单选按钮显示表单上数据集的值。 [英] how to display values from datasets on the form using GroupBox and radio buttons.

查看:153
本文介绍了如何使用GroupBox和单选按钮显示表单上数据集的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,其中有7个问题。使用包含问题和答案表的数据集在表单上显示问题。

在数据集项目0,1,2,3,4中包含问题编号,问题,第一个选项,第二个选项和第三种选择。

我想知道是否有更好的方法来加载问题。

我使用GroupBox将单选按钮分组为三组。

I have a form in which there are 7 questions. The questions are displayed on the form using dataset containing a table of questions and answers.
In the dataset items 0, 1,2,3,4 contains the question number, question, first option, second option and third option respectively.
I want to know if there is a better way of loading the questions.
I have grouped the radio buttons into sets of three using GroupBox.

Label2.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label1.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton1.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton2.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton3.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1

         Label4.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label3.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton4.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton5.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton6.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1

         Label5.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label6.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton7.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton8.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton9.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1


         Label15.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label8.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton10.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton11.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton12.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1


         Label9.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label10.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton13.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton14.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton15.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1

         Label11.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label12.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton16.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton17.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton18.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1

         Label13.Text = ds.Tables("AddressBook").Rows(a).Item(0)
         Label14.Text = ds.Tables("AddressBook").Rows(a).Item(1)
         RadioButton19.Text = ds.Tables("AddressBook").Rows(a).Item(2)
         RadioButton20.Text = ds.Tables("AddressBook").Rows(a).Item(3)
         RadioButton21.Text = ds.Tables("AddressBook").Rows(a).Item(4)
         a = a + 1

推荐答案

由于您要多次显示问题,我建议您创建自己的用户控件。



在用户控件中,您可以为数字和问题添加2个标签,为选项添加3个单选按钮。然后包括类属性以保留问题编号和选项。您还可以在控件内编写更多操作。



构建项目后,您应该能够将控件拖放到表单中。



关于如何在这里制作控件的更多教程

制作用户控件
Since you are going to show the question multiple time then I suggest you to create your own User Control.

Inside the user control you can put 2 labels for the number and question and three radio button for the options. Then include class properties to keep the questions number and options.You can also program more actions inside the control.

After building the project, you should be able to drag and drop the control into the form.

More tutorial on how to make the controls here
Making A User Control


这篇关于如何使用GroupBox和单选按钮显示表单上数据集的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆