How do I program a TEXTBOX so that it validates the contents when the user enters some value inside it then presses the <RET> key?
I have an 'Employee Number' box defined as my first text entry field where a user should enter an Employee number then press <RET>
Once the <RET> key is pressed my code should go and check that the data entered exists as an actal employee.
The problem is that I don't be able to find a textbox method or event that caters for this action.
Have tried the event 'Leave' but this only works when I press the <TAB> key when I've finished entering data in the field and also then messes up all my button actions on screen as 'by definition' as soon as I click on buttons unrelated to the Employee textbox my code attempts to complete the 'Leave' defined code for my Employee text box.
Hi Mark,
You could try using the "KeyDown" function.
You can pick up Carriage returns or the down key or end key in fact any keyboard depression.
To pick up the carriage return key code is like this:-
if e::"KeyCode" = type "System.Windows.Forms.Keys"::"Return"
do some code here
end-if
Hope that helps.
Cheers
Neil.
How do I program a TEXTBOX so that it validates the contents when the user enters some value inside it then presses the <RET> key?
I have an 'Employee Number' box defined as my first text entry field where a user should enter an Employee number then press <RET>
Once the <RET> key is pressed my code should go and check that the data entered exists as an actal employee.
The problem is that I don't be able to find a textbox method or event that caters for this action.
Have tried the event 'Leave' but this only works when I press the <TAB> key when I've finished entering data in the field and also then messes up all my button actions on screen as 'by definition' as soon as I click on buttons unrelated to the Employee textbox my code attempts to complete the 'Leave' defined code for my Employee text box.
There is also validation built in to Windows Forms Controls.
If you set the CausesValidation property of the textbox to true then when the textbox loses focus the event Validating will be raised in which you can run your validation code.
If the validation fails then you should set the CancelEventArg::Cancel property to true which stops the validation at that point.
If you do not set the Cancel to true then the Validated event will be raised in which you can execute code to continue.
Example: simple form with two textbox controls:
method-id textBox1_Validating final private.
procedure division using by value sender as object e as type System.ComponentModel.CancelEventArgs.
if textBox1::Text = "999"
set e::Cancel to true
move "bad" to textbox1::Text
invoke textBox1::Focus
end-if
end method.
method-id textBox1_Validated final private.
procedure division using by value sender as object e as type System.EventArgs.
move "good" to textbox1::Text
invoke textBox2::Focus
end method.
How do I program a TEXTBOX so that it validates the contents when the user enters some value inside it then presses the <RET> key?
I have an 'Employee Number' box defined as my first text entry field where a user should enter an Employee number then press <RET>
Once the <RET> key is pressed my code should go and check that the data entered exists as an actal employee.
The problem is that I don't be able to find a textbox method or event that caters for this action.
Have tried the event 'Leave' but this only works when I press the <TAB> key when I've finished entering data in the field and also then messes up all my button actions on screen as 'by definition' as soon as I click on buttons unrelated to the Employee textbox my code attempts to complete the 'Leave' defined code for my Employee text box.
Good and clear examples. Thank you.