在C#中怎样实现像百度中的搜索框中输入第一个字时自动在下面显示相应开头是输入字的所有项?
我想在软件中实现!

解决方案 »

  1.   

    ajax,当你输入时,自动从后台数据库获取相关的信息
      

  2.   

    asp.net 2.0 ajax + ajaxcontroltoolkit 里有 AutoComplete

    http://ajaxcontroltoolkit.com/AutoComplete/AutoComplete.aspx 
      

  3.   

    自己编写 js 调用 webservice 提取数据库数据 ,也可以调用 WebMethod
      

  4.   

    分若干时刻:
    光标出现的时刻 光标离开的时刻 都可以写function  究竟是查词库还是什么db由你了分成细节去看 就好办了
      

  5.   

    他说的是Google  哈哈哈  不是百度
      

  6.   

    抱歉啊!我说错了!就是像迅雷和Google中是搜索框,怪我没有描述清楚!
    ajax听说了这个开发工具  但不知道在软件中能实现不?不是在WEB中。
    网上有这方面的控件不?
      

  7.   

    在地址栏里的提示是IE缓存的作用,比如说像Google的那种下拉菜单似的提示是AJAX技术,需要懂javascript,另外yahoo邮箱也有这种提示
      

  8.   

    你说的那是google的功能吧...百度的那个IE自己特有吧..
      

  9.   

    恩!就是Google的功能!百度用多了打字成惯性了!不知在C#中怎样实现?
      

  10.   

    自動完成功能啊,WINFORM下TextBox和ComboBox都有,==我找我寫的代碼
      

  11.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;namespace NewApp
    {
        class AutoComplete
        {
            List<TextBox> _CompleteObjectList = new List<TextBox>();
            Dictionary<string, AutoCompleteStringCollection> _Source = new Dictionary<string, AutoCompleteStringCollection>();
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=TestDB;Integrated Security=True");
            public AutoComplete()
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("select * from AutoComplete", conn);
                SqlDataReader read = cmd.ExecuteReader();
                while (read.Read())
                {
                    string key = read["name"].ToString();
                    if (!_Source.ContainsKey(key))
                        _Source.Add(key, new AutoCompleteStringCollection());
                    _Source[key].Add(read["str"].ToString());
                }
                read.Close();
                conn.Close();
            }        public void AddAll(Control item)
            {
                for (int i = 0; i < item.Controls.Count; i++)
                {
                    Control var = item.Controls[i];
                    if (var.GetType().Equals(typeof(TextBox)))
                    {
                        Add(var as TextBox);
                    }
                }
            }        public void Add(TextBox text)
            {
                _CompleteObjectList.Add(text);
                text.Leave += new EventHandler(text_Leave);
                text.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                text.AutoCompleteSource = AutoCompleteSource.CustomSource;
                if (!_Source.ContainsKey(text.Name))
                {
                    _Source.Add(text.Name, new AutoCompleteStringCollection());
                }
                text.AutoCompleteCustomSource = _Source[text.Name];
            }        public void Delete(TextBox text)
            {
                _CompleteObjectList.Remove(text);
            }        public void DeleteAll(Control item)
            {
                for (int i = 0; i < item.Controls.Count; i++)
                {
                    Control var = item.Controls[i];
                    if (var.GetType().Equals(typeof(TextBox)))
                    {
                        Delete(var as TextBox);
                    }
                }
            }        public void AutoCompleteClear()
            {
                foreach (AutoCompleteStringCollection var in _Source.Values)
                {
                    var.Clear();
                }
                SqlCommand cmd = new SqlCommand("Delete AutoComplete", conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }        void text_Leave(object sender, EventArgs e)
            {
                TextBox text = sender as TextBox;
                if (text.Text == "")
                    return;
                string key = text.Name;
                if (!_Source.ContainsKey(key))
                {
                    _Source.Add(key, new AutoCompleteStringCollection());
                }
                if (!_Source[key].Contains(text.Text))
                {
                    SqlCommand cmd = new SqlCommand("insert into AutoComplete select '" + key.Replace("'", "''") + "', '" + text.Text.Replace("'", "''") + "'", conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    _Source[key].Add(text.Text);
                    conn.Close();
                }
            }
        }
    }--------------------------------------------------------
    管理自動完成功能的類