private void btnAdd_Click(object sender, EventArgs e) { var newSubject = new Subject(); var addForm = new OneSubjectForm(OneSubjectForm.WorkMode.AddSubject, newSubject); newSubject = addForm.ShowDialog(); if (newSubject != new Subject()) { _subjectList.Add(newSubject); } _subjectList.Fill(); dgvSubjects.DataSource = typeof(List <Subject>); dgvSubjects.DataSource = _subjectList.Value; }
private void btnEdit_Click(object sender, EventArgs e) { if (dgvSubjects.SelectedRows.Count == 0) { return; } var selectedRow = dgvSubjects.SelectedRows[0]; Subject selectedSubject = _subjectList.Find(Convert.ToInt32(selectedRow.Cells[0].Value)); var editForm = new OneSubjectForm(OneSubjectForm.WorkMode.EditSubject, selectedSubject); Subject newSubject = editForm.ShowDialog(); _subjectList.Replace(selectedSubject.SubjectId, newSubject); _subjectList.Update(); dgvSubjects.DataSource = typeof(List <Subject>); dgvSubjects.DataSource = _subjectList.Value; }