private void Departments() { DepartmentsRepository departmentsRepository = new DepartmentsRepository(); var list = departmentsRepository.DepartmentList(); var source = new BindingSource(); list.Insert(0, new Department() { DepartmentNames = "-Select-" }); source.DataSource = list; metroComboBox1.ValueMember = "Id"; metroComboBox1.DisplayMember = "DepartmentNames"; metroComboBox1.DataSource = source; metroComboBox1.SelectedIndex = 0; }
private void frm_select_dept_scrapt_Load(object sender, EventArgs e) { DepartmentsRepository departmentsRepositor = new DepartmentsRepository(); //var _dt = department.DepartmentList(); ////DataRow row = _dt.NewRow(); //row["department_name"] = "Select Department"; //row["id"] = 0; //_dt.Rows.InsertAt(row, 0); //metroComboBox1.DisplayMember = _dt.Columns[1].ToString(); //metroComboBox1.ValueMember = _dt.Columns[0].ToString(); //metroComboBox1.DataSource = _dt; //metroComboBox1.SelectedIndex = 0; }
private void GetDepartments() { try { DepartmentsRepository departmentsRepository = new DepartmentsRepository(); var list = departmentsRepository.DepartmentList(); var source = new BindingSource(); list.Insert(0, new Department() { DepartmentNames = "-Select-" }); source.DataSource = list; cb_department.ValueMember = "Id"; cb_department.DisplayMember = "DepartmentNames"; cb_department.DataSource = source; } catch (Exception ex) { MessageBox.Show(ex.Message); } }