Share via


Moving a Contact into a Contact Group

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Because a contact cannot be in more than one group at a time, you move a contact from one group to another by calling IMessengerGroup::AddContact on the group you want to move the contact to. The Office Communicator server removes the contact from the current group before adding it to the new group.

The contact list is rebuilt by the event handler registered for the DMessengerEvents::OnContactAddedToGroup event.

private void OtherContactsItem_Click(object sender, EventArgs e)
{
  try
  {
    ListViewItem selectedContactItem = contactListView.FocusedItem;
    object contactToAdd = null;
    contactToAdd = communicator.GetContact(listDict[selectedContactItem.Index + 1],
                        communicator.MyServiceId);
    if (contactToAdd != null)
    {
      IMessengerGroups theseGroups = (IMessengerGroups)communicator.MyGroups;
      foreach (IMessengerGroup thisGroup in theseGroups)
      {
         if (thisGroup.Name == sender.ToString())
         {
           thisGroup.AddContact(contactToAdd);
           break;
         }
      }
    }
    selectedContactItem.BackColor = Color.Gray;
  }
  catch (ArgumentException AE)
  {
    MessageBox.Show("Contact List Argument Exception: " +
                  AE.Message.ToString());
  }
  catch (COMException CE)
  {
    MessageBox.Show("Contact List COM Exception: " + 
                    formReturnErrors.returnComError(CE.ErrorCode));
  }
  catch (Exception Ex)
  {
     MessageBox.Show("Contact List Exception: " + Ex.Message);
  }
}

See Also

Concepts

Building a Custom Contact List