数据绑定组合框 [英] Databinding Combobox
本文介绍了数据绑定组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
cboField1.DataBindings.Add("SelectedItem", ds,"Orders2");
我有一个名为Orders2的表,我想将列名绑定到一个组合框.
解决方案
这可能是正确的方法,但是我从来没有使用过相同的方法.解决方案
br/>
您也可以尝试使用这种替代方式将其绑定.
cboField1.DataSource = Orders2 ; cboField1.DisplayMember = //Name of fields to be displayed.<br> cboField1.ValueMember = //Name of field to be kept as value.</br>
如果有帮助,请 投票 和 接受答案 .
助手绑定数据的方法可能是这里的想法
公共 静态 void BindField(ListControl控件,对象 dataSource, 字符串 displayMember, string valueMember) { control.DataTextField = displayMember; control.DataValueField = valueMember; control.DataSource = dataSource; control.DataBind(); }
然后,您可以使用以下内容
BindField(YourComboBoxControl,YourDataSource," ," );
cboField1.DataBindings.Add("SelectedItem", ds,"Orders2");
I have a table named Orders2 and I want to bind the Column names to a combobox. Is the sample code above the correct way of binding data to a combobox?解决方案That could be the right way but I haven''t used the same anytime.
You could also try to bind it using this alternate way.
cboField1.DataSource = Orders2 ; cboField1.DisplayMember = //Name of fields to be displayed.<br> cboField1.ValueMember = //Name of field to be kept as value.</br>
Please vote and Accept Answer if it Helped.
A helper method for binding data might be an idea here
public static void BindField(ListControl control, object dataSource, string displayMember, string valueMember ) { control.DataTextField = displayMember; control.DataValueField = valueMember; control.DataSource = dataSource; control.DataBind(); }
You can then use as follows
BindField(YourComboBoxControl, YourDataSource, "FieldNameYouWantToDisplayInComboBox", "IdYouWantToStoreInComboBox");
这篇关于数据绑定组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文