询问者
ComboBox 绑定数据源后是否能屏蔽默认选择数据源的第一项数据?

问题
全部回复
-
我写了个DEMO,看看能否满足你的要求
public partial class Form7 : Form { public Form7() { InitializeComponent(); } string strCon = "server=.;uid=sa;pwd=123;database=msdb;Min Pool Size=10;"; private void comboBox1_TextChanged(object sender, EventArgs e) { string strSql = " select * from subjeict where name like '" + comboBox1.Text.ToString() + "%'"; DataSet ds = GetDS(strSql); string[] aa = null; aa = new string[ds.Tables[0].Rows.Count]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { aa[i] = ds.Tables[0].Rows[i]["name"].ToString(); } this.comboBox1.AutoCompleteCustomSource.AddRange(aa); this.comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest; this.comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; comboBox1.SelectionStart = comboBox1.Text.Length; } public DataSet GetDS(string str) { SqlConnection con = new SqlConnection(strCon); con.Open(); SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); return ds; } private void Form7_Load(object sender, EventArgs e) { this.comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest; } }
http://blog.csdn.net/zx13525079024 -
Hi 抽屉里的月光,
关于你的需求进展如何, 如果问题得不到解决的话可以在下面这个英文论坛发帖:
Windows Forms General Forum.
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.