private void FillGradesCombo() { GradeRepository gradeRepository = new GradeRepository(); List <GradeModel> gradesList = new List <GradeModel>(); try { DataTable dataTable = gradeRepository.GetAllGrades(); gradesList = TranslateDataTableToGradeModel(dataTable); } catch (Exception ex) { MessageBox.Show("Network error...Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.cmbGrades.SelectedIndexChanged -= new EventHandler(cmbGrades_SelectedIndexChanged); BindingSource bs = new BindingSource(); bs.DataSource = gradesList; cmbGrades.ValueMember = "GradeID"; cmbGrades.DisplayMember = "GradeName"; cmbGrades.DataSource = bs; cmbGrades.SelectedIndex = -1; this.cmbGrades.SelectedIndexChanged += new EventHandler(cmbGrades_SelectedIndexChanged); }
private void FillGradesCombo(long gradeID) { GradeRepository gradeRepository = new GradeRepository(); List <GradeModel> gradeModels = new List <GradeModel>(); DataTable dataTable = new DataTable(); try { dataTable = gradeRepository.GetAllGrades(); gradeModels = TranslateDataTableToGradeModel(dataTable); } catch (Exception ex) { MessageBox.Show("Network error...Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { dataTable.Clear(); dataTable = null; } this.cmbGrades.SelectedIndexChanged -= new EventHandler(cmbGrades_SelectedIndexChanged); BindingSource bs = new BindingSource(); bs.DataSource = gradeModels; cmbGrades.ValueMember = "GradeID"; cmbGrades.DisplayMember = "GradeName"; cmbGrades.DataSource = bs; if (gradeID > 0) { cmbGrades.SelectedValue = gradeID; } else { cmbGrades.SelectedIndex = -1; } this.cmbGrades.SelectedIndexChanged += new EventHandler(cmbGrades_SelectedIndexChanged); if (_lessonPlannerID > 0) { cmbGrades.Enabled = false; } }