| 发表于:2007-10-15 08:46:25 楼主 |
1. 我定义了一个自定义组件如下: using system; using system.collections.generic; using system.componentmodel; using system.drawing; using system.data; using system.text; using system.windows.forms; using system.collections; namespace jxerpcomponent { public partial class jxlabelcombobox : usercontrol { public jxlabelcombobox() { initializecomponent(); this.databindings.collectionchanged+=new collectionchangeeventhandler (databindings_collectionchanged); } void databindings_collectionchanged(object sender, collectionchangeeventargs e) { if ((e.action == collectionchangeaction.add) && (e.element != null) && ((e.element as binding).propertyname == "selectvalue")) //text { binding bd = new binding("selectedvalue", (e.element as binding).datasource, (e.element as binding).bindingmemberinfo.bindingfield); this.combobox.databindings.add(bd); } } private object selectvalue; public object selectvalue { get { this.selectvalue = this.combobox.selectedvalue; return this.selectvalue; } set { this.selectvalue = value; this.combobox.selectedvalue = value; this.invalidate(); } } } 做了一个测试范例: using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.collections; namespace componenttest { public partial class frmjxcontrol : form { public frmjxcontrol() { initializecomponent(); } private void frmjxcontrol_load(object sender, eventargs e) { arraylist al = new arraylist(); al.add(new a("a1",1)); al.add(new a("a2",2)); al.add(new a("a3", 3)); arraylist b1 = new arraylist(); b1.add(new b("b1",1)); b1.add(new b("b2", 2)); this.datagridview1.datasource = al; this.combobox1.datasource = b1; this.combobox1.displaymember = "b1"; this.combobox1.valuemember = "c2"; this.combobox1.databindings.add("selectedvalue", al, "c2"); this.jxlabelcombobox2.datasource = b1; this.jxlabelcombobox2.displaymember = "b1"; this.jxlabelcombobox2.valuemember = "c2"; this.jxlabelcombobox2.datapropertyname = "c2"; this.jxlabelcombobox2.databindings.add("selectvalue", al, "c2"); this.jxlabelcombobox2.enabled = true; } } public class a { public a(string vc1, int vc2) { c1 = vc1; c2 = vc2; } private string c1; public string c1 { get { return c1; } set { c1 = value; } } private int c2; public int c2 { get { return c2; } set { c2 = value; } } } public class b { public b(string vb1, int vc2) { b1 = vb1; c2 = vc2; } private string b1; public string b1 { get { return b1; } set { b1 = value; } } private int c2; public int c2 { get { return c2; } set { c2 = value; } } } } 问题: 每次从grid的第三行跳到第二行时都回报错。 请高手指教。 |
|
|
|
|