我使用c# winform 中的textbox想做出类似Google的输入提示
现在代码如下:
      
          txtComplan.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtComplan.AutoCompleteMode = AutoCompleteMode.Suggest;
        //上面两句是在窗体Load中写的       AutoCompleteStringCollection ac = new AutoCompleteStringCollection();
        List<string> coms = new List<string>();
        private void txtComplan_TextChanged_1(object sender, EventArgs e)
        {
            
            coms.Clear();
            ac.Clear();
            if (txtComplan.AutoCompleteCustomSource != null)
            {
                txtComplan.AutoCompleteCustomSource = null;
            }
            coms = complanys.FindAll(EndsWithSaurus);//complanys是List<string>集合
            for (int i = 0; i < coms.Count; i++)
            {
                ac.Add(coms[i].Trim());
            }            txtComplan.AutoCompleteCustomSource = ac;
        }
 private  bool EndsWithSaurus(String s)
        {
            if(s.Contains(txtComplan.Text.Trim()))
            {
                return true;
            }
            else
            {
                return false;
            }
        }现在情况是我输入的东西它查出来了并放进了AutoCompleteStringCollection 中使用 txtComplan.AutoCompleteCustomSource = ac;绑定后却不显示在文本框下面,比如“办公室陈敏”,我输入“办”这是能查出来并绑定上去,但如果我输入“陈”它也能查出来 就是不显示出来。
高手指教下 谢谢

解决方案 »

  1.   

       1 楼 发的是我的头像..  这是干啥子勒??? winfrom  应该也有失件吧. 反正 asp.net 是有直接用的控件,呵呵
      

  2.   

    汗,1楼发的图片怎么是我的头像textBox的自动完成功能就是这样,只显示从第一个字符开始去查询的匹配项,GOOGLE上的也是这样。
      

  3.   

    <img src="http://profile.csdn.net/my/3.jpg"  alt="" /><img src="http://profile.csdn.net/my/1.jpg"  alt="" /><img src="http://profile.csdn.net/my/3.jpg"  alt="" />1楼贴的是这些代码么?
      

  4.   

    Harvey_He  高人呀,你是从哪里抓的这个地址呀?
      

  5.   

    首先,你的textbox控件的AutoPostBack属性要设为true,再一个,TextChanged方法要TextBox失去焦点时才会触发。所以你Changed后,鼠标要点下别处才好使。
    然后,类似Google的输入提示不是在后台写的,是用Ajax写的。建议不要这么写了,客户可没耐心看着不断刷新,再说一刷新,一些控件里的值就都没了。
      

  6.   

    你的txtComplan.AutoCompleteCustomSource = null; 这一句没报错吗,应该是不能为NULL的
      

  7.   

    <img src="http://profile.csdn.net/my/3.jpg"  alt="" /><img src="http://profile.csdn.net/my/1.jpg"  alt="" /><img src="http://profile.csdn.net/my/3.jpg"  alt="" />
      

  8.   


    <img src="http://profile.csdn.net/my/3.jpg"  alt="" /><img src="http://profile.csdn.net/my/1.jpg"  alt="" /><img src="http://profile.csdn.net/my/3.jpg"  alt="" />
      

  9.   

    <img src="http://profile.csdn.net/my/3.jpg"  alt="" /><img src="http://profile.csdn.net/my/1.jpg"  alt="" /><img src="http://profile.csdn.net/my/3.jpg"  alt="" />
      

  10.   

    <img src="http://profile.csdn.net/my/3.jpg"  alt="" /><img src="http://profile.csdn.net/my/1.jpg"  alt="" /><img src="http://profile.csdn.net/my/3.jpg"  alt="" />
      

  11.   

    <img src="http://profile.csdn.net/my/3.jpg"  alt="" /> <img src="http://profile.csdn.net/my/1.jpg"  alt="" /> <img src="http://profile.csdn.net/my/3.jpg"  alt="" />