//Also called from the search form. internal void DisplaySearchResults(SearchParameters searchParams, IEnumerable<TmNode> results) { //I need to cache the enumeration for two reasons: // 1: I access the enumeration to get the count, and to access the nodes. // A new search is done each time the enumeration is iterated (even for counting). // 2: The enumeration searches the treeviews _selected nodes. // I clear the searchtrees selected node when I create the results, // therefore no results are returned if the search was done on the search tree. IList<TmNode> nodes = results.ToList(); if (nodes == null || nodes.Count == 0) MessageBox.Show(string.Format("Sorry, your search for '{0}' in {1} has no results.", searchParams.Description, searchParams.Location)); else { string resultsNodeLabel = string.Format("{0} result{1} for '{2}' in {3}", nodes.Count, nodes.Count == 1 ? "" : "s", searchParams.Label, searchParams.Location); searchTreeView.BeginUpdate(); searchTreeView.ClearSelectedNodes(); TmNode catNode = new CategoryNode(resultsNodeLabel); TmTreeNode newNode = searchTreeView.Add(catNode); if (newNode == null) { MessageBox.Show("Unable to add results to display"); return; } foreach (TmNode node in nodes) catNode.Add(node.DeepCopy()); searchTreeView.SelectNode(newNode); newNode.Expand(); searchTreeView.EndUpdate(); CurrentTreeView = searchTreeView; } }