It is not clear and we tend to miss this when we are deleting groups. So I thought it is worth mentioning it here.
You need to delete the group definition t remove the entry from the project browser. The following code is deleting “Group 1” group definintion.
FilteredElementCollector collector = new FilteredElementCollector(doc);
var groupTypes = from element in collector where element.Name == "Group 1" select element;
Element groupType = groupTypes.First();
BTW, when elements in a group can be deleted with its element all together if you use Delete method. You do not need to use Ungroup method and delete elements one by one.
Group group = elem as Group;
if (null != group)