private void addButton_Click(object sender, EventArgs e) { AddForm addForm = new AddForm(); var result = addForm.ShowDialog(); if (result == DialogResult.OK) { people.Add(addForm.Person); personListBox.Items.Clear(); personListBox.Items.AddRange(people.ToArray()); } //Person addedPerson = addForm.ShowDialog(); //people.Add(addedPerson); //personListBox.Items.Add(addedPerson); }
private void editButton_Click(object sender, EventArgs e) { Person selectedPerson = personListBox.SelectedItem as Person; if (selectedPerson != null) { AddForm editForm = new AddForm(selectedPerson); var result = editForm.ShowDialog(); if (result == DialogResult.OK) { var index = personListBox.SelectedIndex; people.RemoveAt(index); people.Insert(index, editForm.Person); personListBox.Items.RemoveAt(index); personListBox.Items.Insert(index, editForm.Person); } } }