Пример #1
0
        protected override void PerformSearch(string searchTerm, CancellationToken token, ComboTreeNodeCollection results)
        {
            string adoFilter = String.Format("Word LIKE '{0}%'", searchTerm.Replace("'", "''"));

            foreach (DataRow dr in _table.Select(adoFilter))
            {
                token.ThrowIfCancellationRequested();
                results.Add(new ComboTreeNode(dr.Field <string>(0)));
            }
        }
Пример #2
0
        private void AddNode(ComboTreeNodeCollection nodes, KindOfGoods kind)
        {
            var node = new ComboTreeNode(kind.Name)
            {
                Tag = kind, Expanded = true
            };

            nodes.Add(node);
            kind.SubKinds.ForEach(k => this.AddNode(node.Nodes, k));
        }
Пример #3
0
        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;
            }
        }
    void _services_TextChanged(object sender, EventArgs e)
    {
        // cancel any existing search operation
        if (_cts != null)
        {
            _cts.Cancel();
            _cts.Dispose();
            _cts = null;
        }

        if (_services.Length > 0)
        {
            if (!_inSearchMode)
            {
                EnterSearchMode();
            }

            if (_services.Length >= MinSearchTermLength)
            {
                // start async search operation
                BeginUpdate();
                Nodes.Clear();
                Nodes.Add(new ComboTreeNode("Searching...")
                {
                    Selectable = false, FontStyle = FontStyle.Italic
                });
                EndUpdate();

                _cts = new CancellationTokenSource();
                ComboTreeNodeCollection results = new ComboTreeNodeCollection(null);

                var task = Task.Factory.StartNew(() => OnPerformSearch(new PerformSearchEventArgs(_services.Text, _cts.Token, results)), _cts.Token);

                task.ContinueWith(t => {
                    if (t.IsFaulted)
                    {
                        results.Clear();
                        string errorText = t.Exception.InnerExceptions.Select(x => x.Message).FirstOrDefault() ?? "an error occured";
                        results.Add(new ComboTreeNode(String.Format("({0})", errorText))
                        {
                            Selectable = false, FontStyle = FontStyle.Italic
                        });
                    }

                    if (!t.IsCanceled)
                    {
                        ApplySearchResults(results);
                    }
                });
            }
            else
            {
                // wait until the search term is long enough
                BeginUpdate();
                Nodes.Clear();
                string msg = String.Format("(type at least {0} characters)", MinSearchTermLength);
                Nodes.Add(new ComboTreeNode(msg)
                {
                    Selectable = false, FontStyle = FontStyle.Italic
                });
                EndUpdate();
            }
        }
        else
        {
            if (_inSearchMode)
            {
                LeaveSearchMode(false);
            }
        }
    }