如何在单行中添加多个主题 [英] How to add multiple subject in single row

查看:84
本文介绍了如何在单行中添加多个主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有一个表单,其中包含一个用于名称的文本框和多个用于主题的复选框
现在,一个表具有两个字段,其中一个用于主题,一个用于主题.一个人可以从该表格中为该表添加名称和任意数量的主题.我该怎么办,请帮忙.

我想补充的一件事是,主题是多个意味着任意数量.

问候,

Brijesh

解决方案

可能有两种方法可以实现相同的目标.
1.在表中,每个选定的主题都有一行.在这种情况下,您可能需要一个单独的自动增量ID字段作为主键.
2.您可以在主题字段中保存逗号分隔的主题.尽管当您需要执行搜索时这会很麻烦.

因此,我建议采用方法1.但是,您需要考虑应用程序的所有方面来做出决定.

基于OP注释的扩展方法1:
您可以创建一个表,其中包含诸如ID,Name和Subject的列.这里的ID是PK,是一个自动递增的字段.

现在,当用户提交表单时,获取所有选定的主题并将其作为单独的行插入.这样您的表格就会显示为
1 Milind英语
2 Milind Physics
3 Milind Chemistry
等等.

现在,当您要搜索时,可以从名称="Milind"的表中选择**
这将为您提供用户选择的所有主题.

Milind


使用字符串生成器类附加用户选择的所有主题,并用逗号(,)分隔.这样一来,您便可以轻松地识别并轻松地出于任何目的从数据库中进行检索.



 StringBuilder subject =  StringBuilder( 1000 );
 (i =  0 ; i< n; i ++) > 
  如果(rblist [i] .slected = )
    subject.Append(rblist [i] .text + ' ,'); 


您可以通过以下两种方法进行操作:从数据库中读取每个主题时,为每个主题动态添加一个CheckBox-这并不困难,只是一个

 CheckBox cb = 新建 CheckBox(); 

并设置其Checked和Text属性,但是您必须将其添加到表单(或例如面板)的控件列表-这意味着正确设置大小和位置,并确保容器设置为自动滚动以使用户可以看到它们.

另一种方法听起来更复杂,但更加灵活:将DataGridView与DataGridViewCheckBoxColumn一起使用.这将帮助您做到这一点:将CheckBox添加到C#DataGridView [ 解决方案

There could be two ways to achieve the same.
1. You have one row in the table for each subject selected. In this case, you may need a separate autoincrement ID field as primary key.
2. You can save comma separated subjects in the subject field. Though this will be cumbersome when you need to perform a search.

So I would suggest to go with approach 1. However, the decision needs to be taken by you considering all the aspect of your application.

Expanding approach 1 based on OP comment:
You can have a table with columns like ID, Name and Subject. Here ID is PK and is an auto-increment field.

Now when the user submits the form, Get all the selected subject and insert it as separate rows. So your table will read
1 Milind English
2 Milind Physics
3 Milind Chemistry
and so on.

Now when you want to search you can search select * from table where name = ''Milind''
which will give you all the subjects selected by the user.

Milind


Use string builder class to append all the subjects selecgted by the user seperated by a comma(,). So that u can identify easily and retrieve easily from the database for any purpose.



StringBuilder subject=new StringBuilder(1000);
for(i=0;i<n;i++)>
  if(rblist[i].slected=true)
    subject.Append(rblist[i].text+',');


There are a couple of ways you can do this: Dynamically add a CheckBox for each subject when you read them from the database - that isn''t difficult, it''s is only a

CheckBox cb = new CheckBox();

plus setting its Checked and Text properties, but then you have to add it to the Controls List of the form (or a panel for example) - which means setting the size and location correctly, and making sure that the container is set to scroll automatically so the user can see them.

The other way sounds more complex, but it is a lot more flexible: use a DataGridView with a DataGridViewCheckBoxColumn. THis will help you do that:
Add CheckBox to C# DataGridView[^]


这篇关于如何在单行中添加多个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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