A contact can also be moved to the "Other Contacts" group from a user-defined group. Moving a contact to the "Other Contacts" group involves removing the contact from the user-defined group with the IMessengerGroup::RemoveContact method.

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

Copy Code

Copy Code
private void removeFromGroupItem_Click(object sender, EventArgs e)
{
  try
  {
	ListViewItem selectedContactItem = contactListView.FocusedItem;
	if (selectedContactItem.Text.Length > 0)
	{
	object contactToRemove = null;
	contactToRemove = communicator.GetContact(listDict[selectedContactItem.Index + 1],
					 communicator.MyServiceId);
	if (contactToRemove != null)
	{
		IMessengerGroups theseGroups = (IMessengerGroups)communicator.MyGroups;
		foreach (IMessengerGroup thisGroup in theseGroups)
		{
		if (thisGroup.Name == selectedContactItem.Group.Header)
		{
			thisGroup.RemoveContact(contactToRemove);
			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