在comboBox1_TextChanged事件里
System.Data.DataTable dt = publicDataTable.Loader.QuerySql("select goodname from good where goodname like '%"+comboBox1.Text.Trim()+"%'");
for(int i=0;i<dt.Rows.Count;i++)
{
this.comboBox1.Items.Add(dt.Rows[i][0].ToString());
}
this.comboBox1.DroppedDown = true;PS:publicDataTable.Loader.QuerySql()方法是我自己写的一个返回一个DataTable 的方法
System.Data.DataTable dt = publicDataTable.Loader.QuerySql("select goodname from good where goodname like '%"+comboBox1.Text.Trim()+"%'");
for(int i=0;i<dt.Rows.Count;i++)
{
this.comboBox1.Items.Add(dt.Rows[i][0].ToString());
}
this.comboBox1.DroppedDown = true;PS:publicDataTable.Loader.QuerySql()方法是我自己写的一个返回一个DataTable 的方法
http://community.csdn.net/Expert/topic/5684/5684900.xml?temp=.9734461
this.comboBox1.Items.Clear();//连接数据库,填充数据集
string mySql = "select C from B where C like '%"+comboBox1.Text.Trim()+"%'";
SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=A");
SqlDataAdapter myDapter=new SqlDataAdapter(mySql,conn);
DataSet ds=new DataSet();
myDapter.Fill(ds);//填充comboBox的下拉项
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
this.comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}
this.comboBox1.Items.Clear();//连接数据库,填充数据集
string mySql = "select C from B where C like '%"+comboBox1.Text.Trim()+"%'";
SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=A");
SqlDataAdapter myDapter=new SqlDataAdapter(mySql,conn);
DataSet ds=new DataSet();
myDapter.Fill(ds);//comboBox的绑定
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
comboBox1.DataSource=ds.Tables[0].DefaultView;
comboBox1.DisplayMember="C";
comboBox1.ValueMember="C";
}
设置 DataSource 属性后无法修改项集合。