I've never handled keysroke events before and I would like to implement a Return keystroke event in a Windows form to bring up a list of items in a datagrid as well as habing a search button in the form.
With the help of a tutorial, I have coded the following event:
and have assigned the event handler in the constructor of my Form, with the following line:
I have also been told that the KeyPress event does not handle control keys, so I am using the ProcessDialogKe y() library to override it in the method, but cannot assign this to the ProcessDialogKe y method group (commented out part).
Unfortunately, nothing happens when I press return with the code as it stands. And, when I first tried implementing it, the form would EXIT when return was pressed, but I don't know how that would have happened?
Am I missing something? Please advise.
Matt
With the help of a tutorial, I have coded the following event:
Code:
private void ReturnResults(object o, KeyPressEventArgs e) { char c = e.KeyChar; if (c == (char) Keys.Return) { SearchAdmin(); } else { e.Handled = false; } base.ProcessDialogKey(Keys.Return); }
Code:
this.KeyPress += new KeyPressEventHandler(ReturnResults); //this.ProcessDialogKey += new KeyPressEventHandler(ReturnResults);
Unfortunately, nothing happens when I press return with the code as it stands. And, when I first tried implementing it, the form would EXIT when return was pressed, but I don't know how that would have happened?
Am I missing something? Please advise.
Matt
Comment