private PeptideGroupDocNode ExcludePeptides(PeptideGroupDocNode peptideGroupDocNode) { var excludedPeptides = new HashSet <IdentityPath>(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { var row = dataGridView1.Rows[i]; var rowTag = (Tuple <IdentityPath, PeptideDocNode>)row.Tag; if (!(bool)row.Cells[PeptideIncludedColumn.Name].Value && ReferenceEquals(rowTag.Item1.GetIdentity(0), peptideGroupDocNode.Id)) { excludedPeptides.Add(rowTag.Item1); } } var nodeGroupNew = peptideGroupDocNode.ChangeChildrenChecked(peptideGroupDocNode.Molecules.Where(pep => !excludedPeptides.Contains(new IdentityPath(peptideGroupDocNode.PeptideGroup, pep.Id))).ToArray()); if (!ReferenceEquals(nodeGroupNew, peptideGroupDocNode)) { nodeGroupNew = nodeGroupNew.ChangeAutoManageChildren(false); } return((PeptideGroupDocNode)nodeGroupNew); }