Q:

.NET winform - Checkbox nullReferenceException

When im trying to set checkbox.checked, i got null refedence exception. I dont know why, it looks like that checkbox isnt initialized. 
There is my code 
public UpdateProduct(DataGridViewRow row,Form1 form)
{
    this.row = row;
    this.form = form;
    product = row.DataBoundItem as object;
    visibilityCheckBox.Checked = true;
    InitializeComponent();
}

Exception is firing in line visibilityCheckBox.Checked = true;
Please can anybody help me with this issue ? Thanks much ! 

A:

I guess you didn't call InitializeComponent before, and since you are trying to set it before the call to InitializeComponent, visibilityCheckBox will be null.
Call InitializeComponent first or write another method that does only update the created UI elements.

