private void AddTrBtn_Click(object sender, EventArgs e) { var tr = new TrainingAddForm() { Training = new Training() { Date = DateTime.Now, Time = DateTime.Now, Duration = DateTime.Now } }; if (tr.ShowDialog(this) == DialogResult.OK) { TrainigsList.Add(tr.Training); TrListBox.DataSource = null; TrListBox.DataSource = TrainigsList; if (TrainigsList.Count != 0) { InfoChange(TrainigsList[0]); } } }
private void editBtn_Click(object sender, EventArgs e) { int index = TrListBox.SelectedIndex; if (index != ListBox.NoMatches) { var item = (Training)TrListBox.Items[index]; var ff = new TrainingAddForm() { Training = item, Label = "Редактирование", Button = "Изменить" }; if (ff.ShowDialog(this) == DialogResult.OK) { TrainigsList.Remove(item); TrainigsList.Insert(index, item); TrListBox.DataSource = null; TrListBox.DataSource = TrainigsList; InfoChange(item); } } }