The following code snippet from the complete code sample iterates on a collection of IMessengerGroup objects. Each individual group is passed into the createGroupListItem(IMessengerGroup) and a ListViewGroup item is returned. The new ListViewGroup, groupItem is added to the Items collection of the ListView, contactListView.

Copy Code
contactGroups = (IMessengerGroups)communicator.MyGroups;
 if (contactGroups != null)
 {
	foreach (IMessengerGroup contactGroupItem in contactGroups)
	{
	ListViewGroup newGroup = createGroupListItem(contactGroupItem);
	contactListView.Groups.Add(newGroup);
	ListViewItem groupItem = new ListViewItem(newGroup);
	contactListView.Items.Add(groupItem);
}
 }

See Also