Ron

Ron

  • NA
  • 44
  • 64.4k

Move to next control on Enter

Sep 7 2010 1:23 PM

I have a combobox + several textbox's on a form. Apparently the default behaviour for the comboxbox is to validate the content when the tab key is pressed, then move to the next control in the tab order. I would like to mimic this behavior when the 'Enter' key is pressed. So far I've done this:

private void cmbVendorList_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)

MessageBox.Show("hello");
}

I need to replace the messagebox with some code that will cause the combobox to validate, then move to a textbox. Any suggestions or input on a better way to accomplish this task?
 
Update: I found that placing this code: 'txtMy.focus' in place of the messagebox complished this task. However that leads to ask a more general question: The focus event does not appear in the properties window of the C# environment that I'm using. I found this to be true of several properties/events I've tried to use in the past. Is it because I'm using C# 2008 Express Edition?

Answers (4)