在TextBox集合中,我從數據庫表中加載數據,它包含像這樣的數據「01-carrot」我爲文本框設置了AutoCompleMode。但如果我輸入'01'它顯示相關的集合,但如果我在開始時輸入'c'它不顯示任何集合請建議我C#,Visual Studio 2008
我試過Code Like This,並且在Load_page事件中加載了這個enter code here
。
AutoCompleteStringCollection MyCollection;
private void clubitem_no()
{
try
{
// string a = txtitem.Text + "%";
// DataTable allnames = new DataTable();
// MySqlCommand cmdauto = new MySqlCommand("SELECT CONCAT(product_id,'-',product_name)AS product_name FROM product_details WHERE product_id LIKE '"+ a + "' OR product_name LIKE '" + a + "'", conn);
MySqlCommand cmdauto = new MySqlCommand("SELECT CONCAT(product_id,'-',product_name)AS product_name FROM product_details ", conn);
conn.Open();
MySqlDataReader newdr = cmdauto.ExecuteReader();
MyCollection = new AutoCompleteStringCollection();
while (newdr.Read())
{
string b = newdr.GetString(0);
MyCollection.Add(newdr.GetString(0));
}
// txtitem.AutoCompleteCustomSource = MyCollection;
txtitem.AutoCompleteMode = AutoCompleteMode.Suggest;
txtitem.AutoCompleteSource = AutoCompleteSource.CustomSource;
// AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();
txtitem.AutoCompleteCustomSource = MyCollection;
newdr.Close();
conn.Close();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
conn.Close();
}
}
標準自動完成只從文本的開始搜索。如果您希望在文本中間進行搜索,則必須自己編寫邏輯自動填充或使用第三方組件。 –