private void btnAdd_Click(object sender, EventArgs e) { try { List <Company> lstComp = gridComp.DataSource as List <Company>; bool temp = lstComp.Exists(cmp => cmp.CompanyName.ToLower().Replace(" ", "") == txtComp.Text.ToLower().Replace(" ", "")); if (!temp && !string.IsNullOrEmpty(txtComp.Text)) { Company tempComp = new Company(); tempComp.ID = string.IsNullOrEmpty(lblCmpInfo.Text) ? 0 : Convert.ToInt32(lblCmpInfo.Text); tempComp.CompanyName = txtComp.Text; mngStock.CreateOrUpdateCompany(tempComp); GetProductAndCompany(); HideCompanyLabels(); MessageBox.Show("This item successfully added/updated.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Logger.WriteErrorMessage(ex); } }