C# Textbox and AutoCompleteMode Conflicts with KeyPress.

Filed Under (Code) by Mystalia on 11-07-2008

Tagged Under : , , , , ,

Ok, personally I was using a textbox and when you pressed “Enter” it would complete a task, BUT I also wanted the textbox to be autocompletive (if that’s a valid term).

When I actually went to test it all out I found that instead of running the Keypress event, it just highlighted the text and did nothing else… Googled to find there is no valid reason why, but there is a work around, and it’s simple.

Abandon KeyPress and use the KeyDown function, setup your keydown event correctly, and it will work.

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