private void EditButton_Click(object sender, EventArgs e) { var index = ServiceListBox.SelectedIndex; if (index >= 0 && ServiceListBox.GetSelected(index)) { var crash = Car.CrashHistory[index]; if (DescTb.Text != crash.Description && DescTb.Text != "" || DateTp.Value != crash.Date || SeriousCb.Checked != crash.IsSerious) { crash.Description = DescTb.Text; crash.Date = DateTp.Value; crash.IsSerious = SeriousCb.Checked; ServiceListBox.DataSource = null; ServiceListBox.DataSource = Car.CrashHistory; } else { MessageBox.Show("Введите изменения!"); } } }
private void DeleteButton_Click(object sender, EventArgs e) { var index = ServiceListBox.SelectedIndex; if (index >= 0 && ServiceListBox.GetSelected(index)) { var crash = Car.CrashHistory[index]; Car.CrashHistory.Remove(crash); ServiceListBox.DataSource = null; ServiceListBox.DataSource = Car.CrashHistory; DateTp.Value = DateTime.Today; DescTb.Text = ""; SeriousCb.CheckState = CheckState.Unchecked; } }
private void ServiceListBox_Click(object sender, EventArgs e) { var index = ServiceListBox.SelectedIndex; if (index >= 0 && ServiceListBox.GetSelected(index)) { var crash = Car.CrashHistory[index]; DateTp.Value = crash.Date; DescTb.Text = crash.Description; if (crash.IsSerious) { SeriousCb.CheckState = CheckState.Checked; } else { SeriousCb.CheckState = CheckState.Unchecked; } } }