void dsbListItems_PerformSearch(object sender, PerformSearchEventArgs e) { if (chkRetainGroups.Checked) { foreach (ComboTreeNode node in dsbListItems.AllNormalNodes) { e.CancellationToken.ThrowIfCancellationRequested(); if (dsbListItems.DefaultSearchPredicate(node, e.SearchTerm)) { // get all ancestor nodes (including the result) Stack <ComboTreeNode> ancestors = new Stack <ComboTreeNode>(); ComboTreeNode current = node; while (current != null) { ancestors.Push(current); current = current.Parent; } // copy ancestor nodes into search results (or re-use existing) ComboTreeNodeCollection collection = e.Results; while (ancestors.Any()) { current = ancestors.Pop(); ComboTreeNode copy = e.Results.Find(x => dsbListItems.DefaultEquivalencePredicate(x, current), true); if (copy == null) { collection.Add(copy = current.Clone()); } collection = copy.Nodes; } } } e.Handled = true; } }