如何将一列绑定到几个checbox控件,取决于该列中的值 [英] How bind one column to few checbox controls, depends on value in that column

查看:54
本文介绍了如何将一列绑定到几个checbox控件,取决于该列中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有int值的列和其他文本列的数据表。我已将所有文本列绑定到textbox和combobox控件。现在我尝试将带有int值的一列绑定到四个复选框控件,这意味着:

- 如果值== 1则首先选中复选框

- 如果值== 2然后检查第二个复选框等。

我不希望将4列插入数据库并将每个复选框绑定到特定列。可以绑定复选框取决于列中的值吗?

I'd have datatable with one column with int values and with others text columns. I have bind all text columns to textbox and combobox controls. Now I try bind one column with int values to four checkbox controls, thats mean:
- if value == 1 then first checkbox ist checked
- if value == 2 then second checkbox ist checked, etc.
I don't want insert 4 columns to database and bind each checkbox to specific column. It's possible to bind checkbox depends of value in column?

推荐答案

我无法理解其中的问题。请参考:



I could not understand what is the problem in it. Please refer :

if (your value==1)
{
 yourfirstcheckbox.checked=true;
}
else if(your vaue==2)
{
 yoursecondcheckbox.checked=true;
}







在这里阅读更多: http://books.google.co.in/books?id=F-yo896Vh4MC&pg=PA143&lpg=PA143&dq=make+checkbox+checked+property+true+dynamically+in+c%23&source= BL&安培; OTS = bVMG3NgaZl&安培; SIG = l1GD8jP12tj1Of3HA5RD4wBReU4&安培; HL = EN&安培; SA = X&安培; EI = SeAoVNbWGIWWyQT3ioGoDQ&安培; VED = 0CFcQ6AEwCQ#v = onepage&安培; q =作出%20checkbox%20checked%20property%20true%20dynamically%20英寸%20C%23安培; f = false [ ^ ]


我以这种方式将控件绑定到数据集:



I bind controls to dataset in that way:

comboBoxDate.DisplayMember = "date";
comboBoxDate.ValueMember = "id";
comboBoxDate.DataSource = ds.Tables[0];

checkBox1.DataBindings.Add("Checked", ds.Tables[0], "columnName1");
checkBox2.DataBindings.Add("Checked", ds.Tables[0], "columnName2");
comboBox1.DataBindings.Add("SelectedValue", ds.Tables[0], "columnName3"); etc.





如果每个控件绑定到特定列,一切正常。但是我希望将一行ds.Tables绑定到几个checkBox控件依赖于该列中的值(以避免dataTable中的许多列)。



临时我为每个chekbox控件制作了单独的列。



Everything works fine if each control is bind to specific column. But I want bind one column of ds.Tables to few checkBox controls depends on value in that column (to avoid many columns in dataTable).

Temporarly I made seperate column for each chekbox control.


这篇关于如何将一列绑定到几个checbox控件,取决于该列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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