C# WinCE下ComboBox实现模糊搜索代码集合

发布时间:2020-05-11 10:53:52 作者:Leah
来源:亿速云 阅读:477

这篇文章主要为大家详细介绍了C# WinCE下ComboBox实现模糊搜索的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

private ComboBox ComboBoxCurrent = new ComboBox();

       private ListView ListViewCurrent = new ListView();
       private string strFlag = "";
       private void P_DefinListViewPosition( Panel panelTemp)
       {
           System.Drawing.Point Location = new System.Drawing.Point(0, ComboBoxCurrent.Location.Y + ComboBoxCurrent.Height);
           int Height = panelTemp.Height - (ComboBoxCurrent.Location.Y + ComboBoxCurrent.Height) - 30;
           if (Height < 60)
           {
               Location = new Point(3, 50);
               Height = ComboBoxCurrent.Location.Y - 50;
           }
           ListViewCurrent.Location = new Point(3, Location.Y + panelTemp.Location.Y);
           ListViewCurrent.Height = Height;
           ListViewCurrent.BackColor = Color.LightBlue;
           //ListViewCurrent.Items[0].BackColor = System.Drawing.Color.Blue;
           //ListViewCurrent.Items[0].Selected = true;
           this.ListViewCurrent.Visible = true;
       }
       private void P_ListView_ICItem_DoubleClick(object sender, EventArgs e)
       {
           ListViewCurrent.Visible = false;
           if (ListViewCurrent.SelectedIndices.Count == 0)
           {
               return;
           }
           DataRow row = this.ListViewCurrent.Items[this.ListViewCurrent.SelectedIndices[0]].Tag as DataRow;
           //strFlag
           ComboBoxCurrent.Text = row["FName"].ToString();
           ComboBoxCurrent.Tag = row;
           ComboBoxCurrent.Focus();
       }
       private void P_ListView_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Return)
           {
               P_ListView_ICItem_DoubleClick(sender, e);
               return;
           }
           if (e.KeyCode == Keys.Escape)
           {
               ListViewCurrent.Visible = false;
               ComboBoxCurrent.Focus();
               return;
           }
       }
       private void P_comboBox_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Return /*&& listViewToControl.Visible == false*/)
           {
               string FNumber = ComboBoxCurrent.Text.Trim();
               if (FNumber.Length < 2)
               {
                   labelStatus.Text = "搜索条件太短,请输入查询条件!";
                   return;
               }
              string strSQL = @"select  top 50
t_ICItem.FItemID
,t_ICItem.FNumber
,t_ICItem.FName
,t_ICItem.FModel
,t1.FName as FUnitName
from t_ICItem Left Join t_MeasureUnit t1 on t_ICItem.FUnitID=t1.FItemID  
where t_ICItem.FNumber like '%" + FNumber + @"%'
or t_ICItem.FName like  '%" + FNumber + @"%'
";
               DataTable tableTemp = new DataTable();
               Cursor.Current = Cursors.WaitCursor;
               uint uiBeginTime = BaseWin32Function.GetTickCount();//计时开始
               if (true != ClassWebService.WebGetDataSetFromService(strSQL, ref tableTemp))
               {
                   labelStatus.Text = "网络超时,请重新操作或检查连网状态!" + CPublicParameters.P_ReturnTimePassed(uiBeginTime).ToString();
                   return;
                   //网络失败,直接返回。
               }
               if (CPublicParameters.GetDataTableCountAll(tableTemp) < 1)
               {
                   labelStatus.Text = "没有查询到任何记录,请重新操作!" + CPublicParameters.P_ReturnTimePassed(uiBeginTime).ToString();
                   return;
               }
               labelStatus.Text = "查找到记录" + CPublicParameters.GetDataTableCountAll(tableTemp).ToString() + @"条,请按上下键选择!" + CPublicParameters.P_ReturnTimePassed(uiBeginTime).ToString();
               CPublicParameters.DatatableSort(ref tableTemp, "FNumber");
               ListViewCurrent.Items.Clear();
               ListViewCurrent.BeginUpdate();
               for (int i = 0; i < CPublicParameters.GetDataTableCountAll(tableTemp); i++)
               {
                   DataRow dtRow = tableTemp.Rows[i];
                   ListViewItem lv = new ListViewItem(new string[] { dtRow["FNumber"].ToString(), dtRow["FName"].ToString() });
                   lv.Tag = dtRow;
                   ListViewCurrent.Items.Add(lv);
               }
               ListViewCurrent.Columns[0].Text = "产品代码";
               ListViewCurrent.Columns[0].Width = 100;
               ListViewCurrent.Columns[1].Text = "名称";
               ListViewCurrent.Columns[1].Width = 140;
               this.ListViewCurrent.EndUpdate();
               P_DefinListViewPosition(panel6);
               return;
           }
           if (e.KeyCode == Keys.Up && ListViewCurrent.Visible == true)
           {
               ListViewCurrent.Focus();
               return;
           }
           if (e.KeyCode == Keys.Down && ListViewCurrent.Visible == true)
           {
               ListViewCurrent.Focus();
               return;
           }
           if ((e.KeyCode == Keys.Escape || e.KeyCode == Keys.F14) && ListViewCurrent.Visible == true)
           {
               ListViewCurrent.Visible = false;
               return;
           }
       }
       private void comboBox10_KeyDown(object sender, KeyEventArgs e)
       {
           ComboBoxCurrent = comboBox10;
           ListViewCurrent = listView1;
           P_comboBox_KeyDown(sender, e);
       }
       private void listView1_ItemActivate(object sender, EventArgs e)
       {
           P_ListView_ICItem_DoubleClick(sender, e);
       }
       private void listView1_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Return)
           {
               P_ListView_ICItem_DoubleClick(sender, e);
               return;
           }
           if (e.KeyCode == Keys.Escape)
           {
               ListViewCurrent.Visible = false;
               ComboBoxCurrent.Focus();
           }

       }

看完上诉内容,你们掌握C# WinCE下ComboBox实现模糊搜索的方法了吗?如果想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. C#中实现INI配置文件的方法
  2. C#如何利用反射将枚举绑定到下拉框详解

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

combobox 模糊搜索

上一篇:配置mysql主主同步模式的详细步骤

下一篇:mysql主从复制的简要步骤

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》