感谢,学习了。很受启发。
我正在写的一个控件。出了点问题,想请教一下,不知道能不能帮忙看看。
我的目的很简单。就是在COMBOBOX的基础上增加一个Label,其它功能COMBOBOX有的都有就行了。
代码如下:
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的第三行跳到第二行时都回报错。
请指教。TKS。
回复 引用