热门IT资讯网

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

发表于:2024-11-28 作者:热门IT资讯网编辑
编辑最后更新 2024年11月28日,这篇文章主要为大家详细介绍了C# WinCE下ComboBox实现模糊搜索的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。private ComboBox Com

这篇文章主要为大家详细介绍了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 50t_ICItem.FItemID,t_ICItem.FNumber,t_ICItem.FName,t_ICItem.FModel,t1.FName as FUnitNamefrom 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实现模糊搜索的方法了吗?如果想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

0