private void BtnChange_Click(object sender, EventArgs e) { comboBoxDepartment.Enabled = true; try { departmentBusinessComponent = new DepartmentBusinessComponent(); var allDepartments = departmentBusinessComponent.FetchDepartments(); comboBoxDepartment.DataSource = allDepartments .Where(d => !d.DepartmentName.Equals(employee.DepartmentInfo.DepartmentName)) .ToList <Department>(); comboBoxDepartment.DisplayMember = "DepartmentName"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void LoadDepartments() { try { departmentBusinessComponent = new DepartmentBusinessComponent(); var departments = departmentBusinessComponent.FetchDepartments(); if (departments != null && departments.Count > 0) { comboBoxDepartment.DataSource = departments; comboBoxDepartment.DisplayMember = "DepartmentName"; } else { MessageBox.Show("no department records found"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }