首页上一页 1 下一页尾页 3 条记录 1/1页
快学快用第10题中,发现combobox中实现自动搜索功能的话,输入检索词W或者标点,检索不出字符W或者标点在首位的内容,其他都可以检索出,以下为代码,请老师解答下。谢谢
发表在C#图书答疑
2021-08-29
《C#编程入门指南》第9章 Windows 控件—C/S 程序的基础
是否精华
是
否
版块置顶:
是
否
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _9710 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] Websx = new string[] { ",.wb", "b.bw,er", "etyw", "wwwhhhhwmingricom", "www126com", "www123com", "kkwkhcasilsemicom", "wwwQQcom" }; private void Form1_Load(object sender, EventArgs e) { comboBox1.DataSource = Websx; comboBox1.Text = ""; } private void comboBox1_TextUpdate(object sender, EventArgs e) { string str = ""; string str1 = comboBox1.Text.ToString(); for (int x = 0; x < Websx.Length; x++) { int y=Websx[x].IndexOf(str1); if (y > 0) { str += Websx[x] + "-"; } } char[] fengef={'-'}; string[] websx1 = str.Split(fengef,StringSplitOptions.RemoveEmptyEntries); comboBox1.DataSource = websx1; comboBox1.SelectedIndex = -1;//输入框默认空 comboBox1.Text = str1;//输入款默认输出搜索字符 } private void comboBox1_TextChanged(object sender, EventArgs e) { comboBox1.SelectionStart = comboBox1.Text.Length;//让输入光标始终在文本末 } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } } }
于2021-08-29 20:04:54编辑