findControl使用问题
public FrmRePrint Form { get; private set; }
public DataRow DataRow { get; private set; }
public Piaost.Order.OrderInfo Info { get; private set; }
public Panel Panel { get; private set; }
public Label tbTime { get; private set; }
public Label tbPeopleNum { get; private set; }
private System.Windows.Forms.Control findControl(System.Windows.Forms.Control control, string controlName)
{
Control c1;
foreach (Control c in control.Controls)
{
if (c.Name == controlName)
{
return c;
}
else if (c.Controls.Count > 0)
{
c1 = findControl(c, controlName);
if (c1 != null)
{
return c1;
}
}
}
return null;
}
private void Init()
{
this.Panel.Tag = this.DataRow;
Label tbTime = (Label)this.findControl(Form.lb_Time, Form.lb_Time.Name);
Label tbPeopleNum = (Label)this.findControl(Form.lb_PeopleNum, Form.lb_PeopleNum.Name);
}
public void Write()
{
tbTime.Text = Info.CreateDate.ToString();
tbPeopleNum.Text = Convert.ToString(Info.OrderBuyNum);
}
上面Write方法代码为对我的一个自定义控件进行赋值,执行到 tbTime.Text = Info.CreateDate.ToString();提示错误为“未将对象引用设置到对象的实例”,首先Info.CreateDate.ToString();是有值的,而且值没问题