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.

Copy Code

Copy Code
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