Skip to main content

UpdateContact

The UpdateContact method saves any changes made on the Edit Contact Information GUI to the current contact instance — represented by curContact. The method is invoked when either the Update or Add buttons are clicked. The method does the following:

  1. Assigns the values currently displayed by the GUI elements to the properties of curContact.

  2. Invokes Save on curContact.

  3. If the status information returned by Save indicates a problem, then UpdateContact displays a message.

  4. If the status information returned by Save indicates success, then UpdateContact does the following:

    1. Invokes RefreshContacts. This method updates the data displayed in the tree on the left hand side of the GUI.

    2. Invokes DisplayContact passing it the object ID of the current contact.

Here is the method. Add the body of the method to the UpdateContact stub in PhoneFormObj.cs.


private void UpdateContact()
{
 curContact.Name
   = (txtConName.Text == "") ? null : txtConName.Text;
 curContact.ContactType
   = (comboBox1.SelectedItem == null) ? 
                                    null : comboBox1.SelectedItem.ToString();
 status = curContact.Save();
 if (!status.IsOK)
 {
   MessageBox.Show(status.Message);
 }
 else
 {
   RefreshContacts();
   DisplayContact(curContact.Id());
  }
}

FeedbackOpens in a new tab