private void listViewList_SelectedIndexChanged(object sender, EventArgs e) { if (listViewList.SelectedItems.Count == 1) { ListStudents list = listViewList.SelectedItems[0].Tag as ListStudents; comboBoxSpec.SelectedIndex = comboBoxSpec.FindString(list.idSpecialty.ToString()); comboBoxKad.SelectedIndex = comboBoxKad.FindString(list.idFirstName.ToString()); } else { comboBoxKad.SelectedItem = null; comboBoxSpec.SelectedItem = null; } }
private void buttonEdit_Click(object sender, EventArgs e) { if (listViewList.SelectedItems.Count == 1 && comboBoxKad.SelectedItem != null && comboBoxSpec.SelectedItem != null) { ListStudents list = listViewList.SelectedItems[0].Tag as ListStudents; list.idSpecialty = Convert.ToInt32(comboBoxSpec.SelectedItem.ToString().Split('.')[0]); list.idFirstName = Convert.ToInt32(comboBoxKad.SelectedItem.ToString().Split('.')[0]); Program.College.SaveChanges(); ShowList(); } else { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewList.SelectedItems.Count == 1) { ListStudents list = listViewList.SelectedItems[0].Tag as ListStudents; Program.College.ListStudents.Remove(list); Program.College.SaveChanges(); ShowList(); } comboBoxKad.SelectedItem = null; comboBoxSpec.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }