数据库自动完成文本框无法正常工作

时间:2016-09-08 09:02:53

标签: c# autocomplete

这是我的代码,我也为每个文本框设置

  

autocomplete = collection,autocompletemode = append,autocompletesource = customsource。

但它只是在textbox24textbox22中执行。有什么问题?

private void Form1_Load(object sender, EventArgs e)
{
    radioButton1.Checked = true;
    label19.Text = "00";
    label18.Text = "00";
    chExport.Checked = true;
    chImport.Checked = false;
    SenderText1.Enabled = false;
    RecieverText1.Enabled = true;
    ImportSum.Enabled = false;           
    SqlConnection Con = new SqlConnection("Data Source=mypro;InitialCatalog=pro1;Integrated Security=True");
    Con.Open();
    UpdateDataGrid();    

    SqlCommand cmd = new SqlCommand("SELECT        PartName,Sender,Reciever,Address,Driver,CarType FROM office", Con);
    SqlDataReader reader = cmd.ExecuteReader();
    AutoCompleteStringCollection MyCollection1 = new AutoCompleteStringCollection();
    AutoCompleteStringCollection MyCollection2 = new AutoCompleteStringCollection();
    AutoCompleteStringCollection MyCollection3 = new AutoCompleteStringCollection();
    AutoCompleteStringCollection MyCollection4 = new AutoCompleteStringCollection();
    AutoCompleteStringCollection MyCollection5 = new AutoCompleteStringCollection();
    AutoCompleteStringCollection MyCollection6 = new AutoCompleteStringCollection();          

    while (reader.Read())
    {
        MyCollection1.Add(reader.GetString(0));
        MyCollection2.Add(reader.GetString(1));
        MyCollection3.Add(reader.GetString(2));
        MyCollection4.Add(reader.GetString(3));
        MyCollection5.Add(reader.GetString(4));
        MyCollection6.Add(reader.GetString(5));                            
    }

    textBox3.AutoCompleteCustomSource = MyCollection1;
    PartName1.AutoCompleteCustomSource = MyCollection1;
    textBox5.AutoCompleteCustomSource = MyCollection2;
    SenderText1.AutoCompleteCustomSource = MyCollection2;
    textBox6.AutoCompleteCustomSource = MyCollection3;
    RecieverText1.AutoCompleteCustomSource = MyCollection3;                      
    textBox9.AutoCompleteCustomSource = MyCollection4;
    textBox24.AutoCompleteCustomSource = MyCollection5;
    textBox22.AutoCompleteCustomSource = MyCollection6;        
    Con.Close();
    dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
}

0 个答案:

没有答案