private void Form2_Load(object sender, EventArgs e)
        {
           AutoCompleteStringCollection myCutomSource = new AutoCompleteStringCollection();            myCutomSource.AddRange(new string[] { "北京理工", "北京师范", "北京航空", "清华大学" });            this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;            this.textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;            this.textBox1.AutoCompleteCustomSource = myCutomSource;
      }
   这样写完全正确 
   我想要加载数据库里面的 结果程序自动退出 有时“尝试读取或写入受保护的内存。这通常指示其他内存已损坏” 错误
   当然读取数据库时候 写在Form2_Load里面 
并且 string select = "select  top 10  Address   from IdentityCard  where  Address   like   '%" + "北" + "%' "; 
也正确 但是 只能输入一次 清空会报错 ,再次输入也报错

解决方案 »

  1.   

    我想要的结果是在 private void textBox1_TextChanged(object sender, EventArgs e)
            {
                 string select = "select  top 10  Address   from   IdentityCard   where   Address   like   '%" + textBox1.Text.Trim() + "%' ";
            }就是根据文本框里面变化的结果 来搜索 
      

  2.   

    是不是代码只能写在 Form2_Load的事件当中。
      

  3.   

    请参考我的资源
    TextBox和ComoBox智能提示功能源代码(类似Google首页的搜索框)http://download.csdn.net/source/1631570
      

  4.   

    AutoCompleteStringCollection AutoComp =;  
    txtbox1.AutoCompleteMode = AutoCompleteMode.Suggest;  
    txtbox1.AutoCompleteSource = AutoCompleteSource.CustomSource;  
    AutoComp.Add("1");   
    AutoComp.Add("2");   
    AutoComp.Add("3");   
    txtbox1.AutoCompleteCustomSource = AutoComp;  
      

  5.   

    有高手解决此问题:http://social.microsoft.com/Forums/nl-NL/2212/thread/25fb6083-f949-40a6-81a1-4c27fc2fec20