I'm working on a system that involves entering a group of values into a series of textboxes, and then clicking on a button that adds the value in each textbox into it's respective List<>.
Once the button has been clicked, I use the Focus() function to put the focus on the textbox at the top of the group of textboxes (txtHR). This works fine when the button is clicked on using the cursor.
The only problem is this:
As there are a lot of textboxes to be written in, I made a function where hitting the Enter key moves the focus down the list of textboxes (making data entry quicker). This leads to the focus then being on the button btnSaveData, and hitting the Enter key again effectively executes the button-click.
This would return the focus to txtHR, but the system then also takes in the Enter key press and moves the focus down into the next textbox.
Is there a way to correct this? I'm guessing it would involve an if/else statement based around whether it was the button click or the key press that calls the txtHR.Focus().
Code for both, btnSaveData_Click and Control_KeyUp, is shown below:
private void btnSaveData_Click(object sender, EventArgs e) //To be clicked while clock is running
{ //turn inputted data into outputted data
//take the data in the input boxes and...
updateLists(); //add to respective list
saveReadings(); //append each variable to file
//return cursor to top box in list ready for next data set
txtHR.Focus();
}
private void Control_KeyUP(object sender, KeyEventArgs e) //for selected textboxes and buttons only
{
if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
{
this.SelectNextControl((Control)sender, true, true, true, true);
}
}
KeyUpevent for the button hooked to that event handler as well?