public void Assign(TreeNodeItems source, bool isNodesHiddenDef)
 {
     Nodes = new List<TreeNodeItem>(source.Nodes.Count);
     foreach (TreeNodeItem item in source.Nodes)
     {
         Assign(item, Nodes, isNodesHiddenDef);
     }
 }
        private void ApplySearchFilter()
        {
            if (_treeView != null && (_treeView.Nodes.Count > 0 || _searching) &&
                FilterNode != null && tbSearch.Text != _inactiveSearchText)
            {
                string filter = tbSearch.Text.Trim();
                if (string.IsNullOrEmpty(filter))
                {
                    if (_searching)
                    {
                        LockTreeUpdate();
                        _treeNodeItems.AssignToTreeNodeCollectionTree(_rootNodes);
                        UnlockTreeUpdate();
                        _treeNodesItemsFiltered = null;
                        SelectFirstFoundNode();
                    }
                    return;
                }

                //Store full TreeView nodes structure
                if (!_searching)
                {
                    _treeNodeItems = new TreeNodeItems(_rootNodes);
                    _searching = true;
                }

                //Create tree nodes filtered items
                _treeNodesItemsFiltered = new TreeNodeItems(_treeNodeItems, true);

                //Lock treeview update and clear nodes list
                LockTreeUpdate();
                _rootNodes.Clear();

                //Apply filter
                foreach (TreeNodeItem nodeItem in _treeNodesItemsFiltered.Nodes)
                {
                    if (_searchResultView == SearchResultView.Tree)
                    {
                        bool canHide = true;
                        ApplySearchFilterTree(nodeItem, filter, ref canHide);
                    }
                    else
                    {
                        ApplySearchFilterList(nodeItem, filter);
                    }
                }

                //Show filtered nodes
                if (_searchResultView == SearchResultView.Tree)
                {
                    _treeNodesItemsFiltered.AssignToTreeNodeCollectionTree(_rootNodes);
                }
                else
                {
                    _treeNodesItemsFiltered.AssignToTreeNodeCollectionList(_rootNodes);
                }

                //Expand all nodes
                _treeView.ExpandAll();

                //Select first found node
                SelectFirstFoundNode();

                //Unlock treeview update
                UnlockTreeUpdate();
            }
        }
 public TreeNodeItems(TreeNodeItems source, bool isNodesHiddenDef)
 {
     Assign(source, isNodesHiddenDef);
 }
        public void CancelSearch()
        {
            if (_searching)
            {
                if (_treeView != null && _treeNodeItems != null)
                {
                    string[] selectedPath = _treeNodesItemsFiltered != null
                        ? _treeNodesItemsFiltered.GetSelectedNodeFullPath(_treeView.SelectedNode)
                        : null;

                    LockTreeUpdate();
                    _treeNodeItems.AssignToTreeNodeCollectionTree(_rootNodes);
                    SelectNodeByPath(selectedPath);
                    UnlockTreeUpdate();

                    _treeNodesItemsFiltered = _treeNodeItems = null;
                }
                _searching = false;
            }
            SetInactiveSearchStyle();
        }