private void Autocomplete() // for customer name
{
try
{
con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT CustomerName FROM Customer where flag='y' ", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
List<string> list = new List<string>();
da.Fill(ds, "Customer");
AutoCompleteStringCollection col = new AutoCompleteStringCollection();
int j = 0;
for (j = 0; j <= ds.Tables[0].Rows.Count - 1; j++)
{
col.Add(ds.Tables[0].Rows[j]["CustomerName"].ToString());
}
txtCustomerName.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtCustomerName.AutoCompleteCustomSource = col;
txtCustomerName.AutoCompleteMode = AutoCompleteMode.Suggest;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例:
我在数据集中有以下条目
如果我在txtCustomerName
中输入R,则它仅显示Roy
和Rony
。它没有显示Roy
两次。
答案 0 :(得分:0)
尝试包含姓氏,因此自动完成知道roy 1与roy 3不同