ComboBox问题:无法绑定到新值成员 [英] ComboBox Issue: Cannot bind to new value member
问题描述
我有一个组合框,我创建了一个用户控件(它实际上是由一个标签,组合框和文本框组成)。我试图绑定一个数据集到组合框数据源,但我不断得到一个错误消息在ValueMember / Display成员:
无法绑定到新的显示成员 - newdisplay member
无法绑定到新值成员 - 参数名称:值
我认为我已经为用户控件正确编码了一切:
public partial class ucComboBox:UserControl
{
#region属性(6)
private bool isEditableReadOnly;
private bool ArrVisible;
private string _value;
private string _name;
public string value
{
get {return _value; }
set {_value = value; }
}
public string name
{
get {return _name; }
set {_name = value; }
}
}
我还有一些其他属性和事件
$ b
我的代码绑定信息:
c $ c>((ucComboBox)ctrl).combobox.DataSource = info;((ucComboBox)ctrl).combobox.ValueMember =radiology_id;
((ucComboBox)ctrl).combobox.DisplayMember =radiology_name;
每当它碰到值成员时,它就会爆炸,我得到上述两个错误。我在我的用户控制中缺少什么?似乎对我这应该是工作..(fyi - info数据源包含两列)
我尝试了一堆不同的战术,没有成功。请帮助!
感谢
不使用Datatset 。创建将保存ID和名称值的类(设施)。将info更改为列表类型。然后下面的代码工作正常:
info.Add(new Facilities {ID = dr [other_facility_id]。ToString ),Name = dr [other_facility_name]。ToString()});
((ucComboBox)ctrl).combobox.DataSource = new BindingSource(info,null); // info;
((ucComboBox)ctrl).combobox.ValueMember =ID;
((ucComboBox)ctrl).combobox.DisplayMember =Name;
没有绑定问题。
I'v got a combobox that I created as a user control(it's actually made up of a label, combobox and textbox). I'm trying to bind a dataset to the combobox datasource, but I keep getting an error message on ValueMember/Display member:
Cannot bind to the new display member - newdisplay member
Cannot bind to the new value member - parameter name: value
I thought I had everything coded correctly for the usercontrol:
public partial class ucComboBox : UserControl
{
#region Properties (6)
private bool isEditableReadOnly;
private bool ArrVisible;
private string _value;
private string _name;
public string value
{
get { return _value ; }
set { _value = value; }
}
public string name
{
get { return _name; }
set { _name = value; }
}
}
I have a few other properties and events in the usercontrol but they shouldnt be the issue.
My code to bind the info:
((ucComboBox)ctrl).combobox.DataSource = info;
((ucComboBox)ctrl).combobox.ValueMember = "radiology_id";
((ucComboBox)ctrl).combobox.DisplayMember = "radiology_name";
It blows up whenever it hits value member, and i get the two errors stated above. Am I missing something in my user control? Seems to me this should be working.. (fyi - the info datasource does contain the two columns)
I've tried a bunch of different tactics with no success. Please help!
Thanks
Moved away from using a Datatset. Created a class("Facilities") that will hold an ID and Name values. Changed "info" to a List type. Then the following code worked just fine:
info.Add(new Facilities { ID = dr["other_facility_id"].ToString(), Name = dr["other_facility_name"].ToString() });
((ucComboBox)ctrl).combobox.DataSource = new BindingSource(info, null);//info;
((ucComboBox)ctrl).combobox.ValueMember = "ID";
((ucComboBox)ctrl).combobox.DisplayMember = "Name";
No issues with binding that.
这篇关于ComboBox问题:无法绑定到新值成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!