如何在C#中通过文本框AutoCompleteMode在列表框中搜索

时间:2019-01-05 11:09:41

标签: c# textbox listbox

我用下面的代码填充“来自数据库的列表框”,并希望通过列表框中具有AutoCompleteMode的文本框进行搜索。请问如何做?

public void refreshdata()
    {
        //DataRow dr;

        SqlConnection cn = new SqlConnection(@"Server=.\SQLEXPRESS; DataBase=Gestion Cabinet; Integrated Security = true;");
        cn.Open();

        SqlCommand cmd = new SqlCommand("select * from Médicaments", cn);
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            listBox1.Items.Add(ds.Tables[0].Rows[i][1]
                + " " + ","
                + ds.Tables[0].Rows[i][2]
                + " " + ","
                + ds.Tables[0].Rows[i][3]);
            cn.Close();
        }

1 个答案:

答案 0 :(得分:0)

请参阅:Search in listbox希望对您有所帮助。