当我试图设置checkbox.checked时,我得到了null refedence异常。我不知道为什么,看起来这个复选框没有初始化。
有我的代码
public UpdateProduct(DataGridViewRow row,Form1 form)
{
this.row = row;
this.form = form;
product = row.DataBoundItem as object;
visibilityCheckBox.Checked = true;
InitializeComponent();
}
异常是在visibilityCheckBox.Checked = true;
任何人都可以帮我解决这个问题吗?非常感谢 !
答案 0 :(得分:3)
我猜您之前没有致电InitializeComponent
,因为您在调用InitializeComponent
之前尝试设置它,visibilityCheckBox
将为null
。
首先调用InitializeComponent
或编写另一个只更新创建的UI元素的方法。