zoukankan      html  css  js  c++  java
  • c# comboBox模糊匹配

    c# comboBox模糊匹配,

    1.系统提供了顺序的匹配方式。

     comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
     comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
    

     本方法的确定是必须是从前往后依次匹配。如:数据项中有“中国人民”,想输入“人民”查询,结果为空。

    2.自己动手做匹配:vs2008

     dtModel = new DataTable();
     string sql1 = "SELECT REPORT_TEMPLATE_CODE ,REPORT_TEMPLATE_NAME FROM REPORT_TEMPLATE WHERE BARGAIN_FORMAT='0' ";
     SystemInfo.dbData.Retrieve(sql1, dtModel);                                
    foreach (DataRow dr in dtModel.Rows) { comboBox1.Items.Add(new ReportName(dr["REPORT_TEMPLATE_CODE"].ToString(), dr["REPORT_TEMPLATE_NAME"].ToString())); } comboBox1.TextUpdate+=new EventHandler(comboBox1_TextUpdate);
     private void comboBox1_TextUpdate(object sender, EventArgs e)
            {
                string key = this.comboBox1.Text;
                DataTable dttemp = dtModel.Clone();
                comboBox1.Items.Clear();
                if (!string.IsNullOrEmpty(key))
                {
                    DataRow[] drs = dtModel.Select(string.Format(" REPORT_TEMPLATE_NAME like '%{0}%' ", key));
                    if (drs != null && drs.Length > 0)
                    {
                        foreach (DataRow drow in drs)
                        {
                            dttemp.Rows.Add(drow.ItemArray);
                        }
                    }
                }
                else
                {
                  dttemp=dtModel;
                }
                foreach (DataRow dr in dttemp.Rows)
                {
                    comboBox1.Items.Add(new ReportTemplet(dr["REPORT_TEMPLATE_CODE"].ToString(), dr["REPORT_TEMPLATE_NAME"].ToString()));
                }
                comboBox1.Select(comboBox1.Text.Length, 0);
                comboBox1.DroppedDown = true;
                Cursor = Cursors.Default;
            }
    
     public class ReportName
        {
           public ReportName(string id, string name)
           {
               this._id = id;
               this._name = name;
           }
            private string _name;
    
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            private string _id;
    
            public string Id
            {
                get { return _id; }
                set { _id = value; }
            }
    
            public override string ToString()
            {
                return this.Name;
            }
        }
    
  • 相关阅读:
    剖析并利用Visual Studio Code在Mac上编译、调试c#程序【转】
    算法题—百灯判熄
    聪明的情侣算法题
    C#中&与&&的区别
    C# 日期格式精确到毫秒 【转】
    C#关于窗体的keysdown事件,无法获取到焦点
    百度,迅雷,华为,阿里巴巴笔试面试
    对 Linux 新手非常有用的 20 个命令
    阿里面试题2015
    Ant工具 ant的安装与配置 ant作用
  • 原文地址:https://www.cnblogs.com/lecone/p/comboBoxAutoComplete.html
Copyright © 2011-2022 走看看