【问题标题】:Close dropdown after pressing enter in autocomplete textbox c#在自动完成文本框c#中按回车后关闭下拉菜单
【发布时间】:2016-05-24 19:51:48
【问题描述】:

我有一个带有自动完成模式的文本框。当我输入任何值时,下拉菜单会出现建议项,我使用向下箭头键向下滚动,当我按 Enter 键时,所选项目被文本框采用,但下拉菜单没有关闭。

如果我使用鼠标单击在建议项中选择任何值,则所选项目将被文本框采用并且下拉菜单会自动关闭。按回车后如何实现此行为?

我没有找到与此问题相关的任何属性。

AutoCompleteStringCollection ac = new AutoCompleteStringCollection();
ac.AddRange(this.Source());

if (textBox1 != null)
{
    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
    textBox1.AutoCompleteCustomSource = ac;
    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
}

【问题讨论】:

    标签: c# winforms autocomplete textbox


    【解决方案1】:

    我发现了问题。

    这是因为在 textBox1_TextChanged 事件上。我有一个代码

    this.AcceptButton=button1;
    

    为了解决,我删除了上面的行。

    对于活动按钮,我使用了以下代码

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                button1_Click(sender, e);
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多