组合框通过两个数据表值绑定 [英] combo box bind through two data table value
本文介绍了组合框通过两个数据表值绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我有两个数据表(dt,dt1)
,其中选择了不同的值.
在dt="gov_center_Name"
和dt1="pri_center_Name"
中选择了这两个值.
现在,我合并此数据表并将值绑定到组合框.
但两者的价值都没有.
解决方案
这是绑定数据表的方式吗?
cmb.DisplayMember = " ; cmb.ValueMember = " ; cmb.DataSource = dt;
dt.Merge(dt1); dt.Columns.Add(" , typeof (字符串)); foreach (DataRow dr in dt.Rows中) { dr [" ] = dr [" gov_center_Name"].ToString(); } foreach (DataRow dr in dt.Rows中) { 如果(dr [" " ) dr [" ] = dr [" pri_center_Name"].ToString(); } comboBox1.DataSource = dt; comboBox1.DisplayMember = " ;
>
hello
i have two datatable (dt,dt1)
in which to different value is selected.
in dt="gov_center_Name"
and dt1="pri_center_Name"
these two value are selected.
now i merge this datatable and bind a value into combobox.
but both value are not coming.
can you suggest me how to do.
解决方案
Is this the way you bind the datatable?
cmb.DisplayMember = "Colname1"; cmb.ValueMember = "Colname2"; cmb.DataSource = dt;
dt.Merge(dt1); dt.Columns.Add("Center", typeof(string)); foreach (DataRow dr in dt.Rows) { dr["Center"] = dr["gov_center_Name"].ToString(); } foreach (DataRow dr in dt.Rows) { if (dr["Center"] == "") dr["Center"] = dr["pri_center_Name"].ToString(); } comboBox1.DataSource = dt; comboBox1.DisplayMember = "Center";
这篇关于组合框通过两个数据表值绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文