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);
}
}