示例#1
0
        protected virtual AutoCompleteEntryCollection FilterList(AutoCompleteEntryCollection list)
        {
            AutoCompleteEntryCollection newList = new AutoCompleteEntryCollection();

            foreach (IAutoCompleteEntry entry in list)
            {
                foreach (string match in entry.MatchStrings)
                {
                    //if (match.ToUpper().StartsWith(this.Text.ToUpper()))
                    string text = CStringUtils.RemoveUnicodeChar(this.Text);
                    if (match.ToUpper().Contains(text.ToUpper()))
                    {
                        newList.Add(entry);
                        break;
                    }
                }
            }
            return(newList);
        }
示例#2
0
        protected virtual void UpdateList()
        {
            object selectedItem = this.list.SelectedItem;

            this.list.Items.Clear();
            //this.list.Items.AddRange(this.FilterList(this.Items).ToObjectArray());
            this.list.DataSource    = null;
            this.list.DisplayMember = "DisplayName";
            this.list.ValueMember   = "Value";
            //this.list.DataSource = this.FilterList(this.Items);
            AutoCompleteEntryCollection filteredSource = FilterList(this.items);

            foreach (AutoCompleteEntry item in filteredSource)
            {
                this.list.Items.Add(item);
            }

            if (selectedItem != null &&
                this.list.Items.Contains(selectedItem))
            {
                EntryMode oldMode = this.Mode;
                this.Mode = EntryMode.List;
                this.list.SelectedItem = selectedItem;
                this.Mode = oldMode;
            }

            if (this.list.Items.Count == 0)
            {
                this.HideList();
                SelectCurrentItem();
            }
            else
            {
                int visItems = this.list.Items.Count;
                if (visItems > 8)
                {
                    visItems = 8;
                }

                this.popup.Height = (visItems * this.list.ItemHeight) + 2;
                switch (this.BorderStyle)
                {
                case BorderStyle.FixedSingle:
                {
                    this.popup.Height += 2;
                } break;

                case BorderStyle.Fixed3D:
                {
                    this.popup.Height += 4;
                } break;

                case BorderStyle.None:
                default:
                {
                } break;
                }

                if (this.PopupWidth <= 0)
                {
                    this.popup.Width = this.Width;
                }
                else
                {
                    this.popup.Width = this.PopupWidth;
                }

                if (this.list.Items.Count > 0 &&
                    this.list.SelectedIndex == -1)
                {
                    EntryMode oldMode = this.Mode;
                    this.Mode = EntryMode.List;
                    this.list.SelectedIndex = 0;
                    this.Mode = oldMode;
                }
            }
        }