无法让我的自定义用户控件将项目从控件本身外部绑定到我的列表框。
SystemUpdateControl.cs:
public partial class SystemUpdateControl : UserControl
{
private BindingList<string> test = new BindingList<string>();
private ListBox lb = new ListBox();
public BindingList<string> tp
{
get { return test; }
set
{
if (value == test)
return;
test = value;
Invalidate();
}
}
public SystemUpdateControl()
{
InitializeComponent();
this.Width = 120;
this.Height = 120;
lb = new ListBox()
{
Width = 100,
Height = 100,
Left = 10,
Top = 10
};
this.Controls.Add(lb);
lb.DataSource = test;
}
}
Form1.cs中:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Task t = Task.Factory.StartNew(addValue);
}
private void addValue()
{
Thread.Sleep(1000);
string[] tst = new string[] { "TEST", "TEST2" };
foreach( string s in tst)
{
systemUpdateControl1.tp.Add(s);
}
}
}
我将向用户控件添加更多项目,我只想在进一步操作之前让这部分工作。任何帮助将不胜感激。