简体   繁体   English

如何阻止Enter键删除ComboBox.Text(带有自动完成功能)?

[英]How to stop Enter key from deleting ComboBox.Text (with AutoComplete)?

SOLVED: The issue was DropDownStyle.Simple 已解决:问题是DropDownStyle.Simple

Every time I press Enter when typing into folderComboBox it deletes the Text. 每次在输入folderComboBox时按Enter键都会删除Text。

It turns out that the problem doesn't occur in a fresh project. 事实证明,在新项目中不会发生此问题。 It only deletes the text when I use auto completion. 仅在使用自动完成功能时才删除文本。

ComboBox folderComboBox = new ComboBox();

void folderComboBox_KeyUp(object sender, KeyEventArgs e)
{

    if (e.KeyCode == Keys.Enter)
    {
        e.SuppressKeyPress = true;
        e.Handled = true;
    }
}
  • I do not have a Form.AcceptButton (mentioned as an issue in another post). 我没有Form.AcceptButton(在另一篇文章中作为问题提及)。

Similar Posts: 类似职位:

  1. Autocomplete on Combobox onkeypress event eats up the Enter key Combobox onkeypress事件上的自动完成会耗尽Enter键
  2. How do I capture the enter key in a windows forms combobox 如何在Windows窗体组合框中捕获Enter键

Solution: 解:

comboBox.DropDownStyle = DropDownStyle.DropDown; //DEFAULT

Issues: 问题:

comboBox.DropDownStyle = DropDownStyle.Simple; //MAIN CAUSE OF ISSUE
comboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox.AutoCompleteSource = AutoCompleteSource.FileSystemDirectories;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM