public void FillProductsToDataGrid(int userCompanyId) { /*This line is block null exception when filling DataGrid.*/ mainForm = (MainForm)Application.OpenForms["MainForm"]; mainForm.mdgProducts.DataSource = new StockDto.StockHeader(); ICollection <StockDto.StockHeader> products = bStock.FillDataGrid(userCompanyId, out ErrorDto error); if (error.ProcessResult) { mainForm.mdgProducts.DataSource = products; mainForm.mlbl_NoProductRecord.Visible = mainForm.mdgProducts.RowCount == 0 ?true :false; } else { Error.Show(error); } }