如何在C#中使用AutoComplete获取事件"项目选择"?

vit*_*izu 5 c# autocomplete

我有使用的代码AutoCompleteStringCollection:

    private void txtS_TextChanged(object sender, EventArgs e)
    {
        TextBox t = sender as TextBox;
        string[] arr = this.dbService.GetAll();

        if (t != null)
        {
            if (t.Text.Length >= 3)
            {
                AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                collection.AddRange(arr);                    
                this.txtSerial.AutoCompleteCustomSource = collection;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

在用户选择自动完成建议后,如何才能获得"项目选择"的事件?和领域的价值?

act*_*ram 7

对于textBox,没有选择项目Event的事情,我相信你正在使用AutoComplete.你可以做的是在你的textBox中添加一个按键事件.在那里你可以验证是否按下了回车键(点击建议的链接与按Enter键相同).像这样的东西:

private void textBox1_KeyDown(object sender, KeyEventArgs e) {
    if (e.KeyData == Keys.Enter) {
        String selItem = this.textBox1.Text;
    }
}
Run Code Online (Sandbox Code Playgroud)