Combox模糊匹配

Combox初始化:
CbxList.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            CbxWorkOperationList.AutoCompleteSource = AutoCompleteSource.ListItems;
            CbxWorkOperationList.DisplayMember = "ItemView";
            CbxList.ValueMember = "ItemGUID";

            _Data = AppServer.GetData();
            _initList = ComboxItemData.ConvertToList(_Data);

            foreach (var item in _initList) {
                CbxWorkOperationList.Items.Add(item.Clone());
            }

            CbxList.DropDownStyle = ComboBoxStyle.DropDown;
            CbxList.DroppedDown = true;

            CbxList.TextUpdate += new EventHandler(CbxList_TextUpdate);
事件:
private void CbxList_TextUpdate(object sender, EventArgs e)
        {
            try
            {
                var input = CbxList.Text.Trim();
                CbxList.Items.Clear();
                List<ComboxItemData> newList = new List<ComboxItemData>();
                foreach (var item in _initList)
                {
                    if (item.ItemView.Contains(input))
                    {
                        CbxList.Items.Add(item.Clone());
                    }
                }
                if (CbxWorkOperationList.Items.Count<=0)
                {

                    CbxWorkOperationList.Items.Add(_initOperationList.ToArray());
                }
                if (input.Length >= 0) {
                    CbxList.SelectionStart = input.Length;
                }
                this.Cursor = Cursors.Default;
                CbxList.DroppedDown = true;

            }
            catch(Exception ex)
            {
                AppHelper.ShowMsg_Error(ex.Message);
            }
        }

 

posted @ 2020-09-23 10:54  大da脸  阅读(307)  评论(0编辑  收藏  举报