下拉式清單方塊輸入文字時和已經輸入的文字最匹配的項自動顯示列出

來源:互聯網
上載者:User

 下拉式清單方塊中有很多項。我想實現這樣的功能:當我在下拉式清單方塊中輸入幾個文字時,和這幾個文字最匹配的項自動顯示列出以供使用者選擇。就像用金山詞霸查單詞時一樣。望知情者速跟貼,不甚感激。

 

在TextChanged事件中加入代碼:  
  private   void   comboBox1_TextChanged(object   sender,   System.EventArgs   e)  
  {  
          string   s=comboBox1.Text;  
          int   iLen=s.Length;  
          ListBox   lstBox1=new   ListBox();  
          for(i=0;i<comboBox1.Items.Count;i++)  
          {  
  if   (comboBox1.Items.IndexOf(i).ToString().Substring(0,iLen)==s)  
  {  
  lstBox1.Items.Add(comboBox1.Items.IndexOf(i).ToString());  
  }  
          }  
  }

 

用ListBox或者ComboBox的FindString好了

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.