与C#中的自动填充文本框相关的问题

时间:2012-07-30 13:15:33

标签: c# vb.net winforms

我有Windows应用程序,我添加了Textbox并设置了AutoCompleteSource属性...

            txt.AutoCompleteMode = AutoCompleteMode.Suggest;
            txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txt.AutoCompleteCustomSource = collection;

我已经从数据库中设置了收集数据..

然而,当用户从Textbox下拉选择一些文本并点击标签移动到其他文本框或控件时......没有任何反应..我的意思是标签键不起作用且Textbox不会丢失其focus(),为什么?什么是解决方案?

1 个答案:

答案 0 :(得分:0)

它应该转到下一个控件 - 除非你在任何textBox1的事件中指定了一些代码。我刚刚检查了这段代码,它工作正常,按下Tab键进入下一个控件:

 public partial class Form1 : Form
 {
    public Form1()
    {
        InitializeComponent();
        string[] array = { "aaa", "abc", "acc", "aac", "acc", "bcc", "cbb", "bbb" };
        //upper line iy my custom array, you get it from database
        AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();
        autoComplete.AddRange(array);
        textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
        textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
        textBox1.AutoCompleteCustomSource = autoComplete;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        //you can use this event to get some data:
        string item = textBox1.Text.Trim();
    }
}

如果你只有这个与textBox相关的代码必须工作!