ffhighwind
ffhighwind

Reputation: 165

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

SOLVED: The issue was DropDownStyle.Simple

Every time I press Enter when typing into folderComboBox it deletes the 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;
    }
}

Similar Posts:

  1. Autocomplete on Combobox onkeypress event eats up the Enter key
  2. How do I capture the enter key in a windows forms combobox

Upvotes: 1

Views: 3185

Answers (1)

ffhighwind
ffhighwind

Reputation: 165

Solution:

comboBox.DropDownStyle = DropDownStyle.DropDown; //DEFAULT

Issues:

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

Upvotes: 1

Related Questions