ComboBox输入数据时检索
来源:互联网 发布:网页游戏平台源码下载 编辑:程序博客网 时间:2024/05/22 12:38
public class ComboBoxCtrl { private ComboBox _ComboBox; private Dictionary<string, string> _Items; public ComboBoxCtrl(ComboBox comboBox) { _ComboBox = comboBox; comboBox.MouseEnter += HandleMouseEnter; comboBox.KeyUp += HandleKeyUp; _Items = new Dictionary<string, string>(); } public void SetItems(Dictionary<string, string> items) { _Items = items; } public void AddItem(string key, string value) { _Items.Add(key, value); _ComboBox.Items.Add(key); } public void ClearItems() { _Items.Clear(); _ComboBox.Items.Clear(); } public string GetValue(string key) { if (_Items.ContainsKey(key)) { return _Items[key]; } else { return "Null"; } } public string GetKey(string value) { foreach (var item in _Items) { if (item.Value == value) return item.Key; } return "Null"; } private void ReloadData() { _ComboBox.Items.Clear(); foreach (var item in _Items.Keys) { _ComboBox.Items.Add(item); } } public void HandleMouseEnter(object sender, EventArgs e) { ReloadData(); } public void HandleKeyUp(object sender, KeyEventArgs e) { string text = _ComboBox.Text; if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) { return; } if (e.KeyCode == Keys.Enter) { _ComboBox.DroppedDown = false; return; } foreach (string item in _Items.Keys) { if (text.Length <= item.Length) { if (item.Substring(0, text.Length) == text) { if (!_ComboBox.Items.Contains(item)) { _ComboBox.Items.Add(item); } } else { _ComboBox.Items.Remove(item); } } else { /*if (text.Substring(0, item.Length) == item) { if (!_ComboBox.Items.Contains(item)) { _ComboBox.Items.Add(item); } } else { _ComboBox.Items.Remove(item); }*/ _ComboBox.Items.Remove(item); } } _ComboBox.DroppedDown = true; } }
测试上面的代码
private ComboBoxCtrl _ComboBoxCtrl; Dictionary<string, string> _Items = new Dictionary<string, string>(); public Form1() { InitializeComponent(); _ComboBoxCtrl = new ComboBoxCtrl(this.comboBox1); InitComboBoxData(); } public void InitComboBoxData() { _Items.Add("aaa","xyt"); _Items.Add("aab", "as"); _Items.Add("bbc", "sd"); _Items.Add("bcd", "df"); _Items.Add("ccd", "cv"); _ComboBoxCtrl.SetItems(_Items); }
- ComboBox输入数据时检索
- jQuery EasyUI Combobox无法检索中文输入的问题
- 运用EasyUI 进行输入框数据检索
- 本地数据 根据输入条件进行检索数据
- combobox 中文首字母检索功能
- ComboBox 输入赛选
- ComboBox实现联想输入
- Flex4 ComboBox 输入中文
- combobox设置不可输入
- 数据检索--区域检索
- Combobox下拉框绑定数据时,注意事项!
- easyui combobox 本地数据实现输入中文拼音简码过滤数据
- 数据检索
- 数据检索
- 检索数据
- C# comboBox为可输入状态时用…
- easyui-Easyui 中 combobox 绑定2000多条数据 自带检索特别卡 如何优化一下
- AjaxControlToolkit ComboBox支持中文检索dll
- 国外嵌入式面试题
- 黑莓开发之环境的搭建
- 《人月神话》笔记:外科手术队伍
- hdu 1013
- mysql查询乱码
- ComboBox输入数据时检索
- 单例模式深入分析
- jQuery插件之表格排序
- Linux系统调用
- java学习笔记(二)--数据的溢出
- Linux内存管理(上)
- 黑莓开发之经典九宫格设计
- Linux之awk命令详解
- 用api在窗口中使用标准控件list