/** * Opens the Member Add/Edit form, but passes no data so it will create * a new Member */ private void btnAddNewMember_Click(object sender, EventArgs e) { Form addMember = new frmMember(); DialogResult button = addMember.ShowDialog(); if (button == DialogResult.OK) { // Cast the contents of the Tag to a member and add to member list members.Add((Member)addMember.Tag); // reload the list box LoadListBox(); } }
/** * Opens the Add/Edit member form with the currently selected Member's data * for editing */ private void btnEditSelectedMember_Click(object sender, EventArgs e) { if (members.Count > 0) { Member m = (Member)lstMembers.SelectedItem; // the syntax below is how Visual Studio sugested I structure this, // rather than the typical `...new frmMember(); update.Tag = m.Clone();` Form update = new frmMember { // Clone the student so the object on this form is only // updated if the DialogResult is OK Tag = m.Clone() }; DialogResult button = update.ShowDialog(); if (button == DialogResult.OK) { LoadListBox(); } } }