Changes

Event Sequences in Visual Basic VB6

2,633 bytes added, 00:05, 15 February 2008
The following lines were added (+) and removed (-):
== Event Table ==* When you click on a control other than the current one, the MouseDown event happens BEFORE the previous control's LostFocus event, and BEFORE the new control's GotFocus event. One valuable use of this is that you can detect the user clicking the Cancel button and programatically avoid running data validation in the LostFocus event of whatever field they were in before clicking Cancel.* The Click event for a Command button happens BEFORE the MouseUp event, while for most other controls, it happens AFTER the MouseUp event.* A number of controls have events that happen BEFORE the GotFocus event. For example, you can build or adjust the list of a ComboBox in the DropDown event before GotFocus. In the Grid control, you get a RowColChange event before the GotFocus event.* When you click in a TextBox, the SelStart property is set (based on the position of the mouse) before ANY other event takes place. == New Validation Event in VB6 ==Visual Basic 6.0 added a new Validate event and CausesValidation property to aid in field-by-field validation. To use the new Validate event, set the CausesValidation property to True for each field that could receive focus, which luckily is the default value for that property. As you leave a field, the Validate event is then generated before any of the focus events (such as LostFocus) are generated. This allows you to validate the data before actually losing focus from the field.If you want to have a field on the form that the user can select without going through any validation, you can set the CausesValidation property to False for that field. For example, if you have a Help or Cancel button, you want to allow the user to select the button without having the current field validated. So set the CausesValidation property for the Help or Cancel button to False. When the user leaves a field and clicks the Help button, the user will be able to view the help without first validating the field.The Validate event has a Cancel parameter. You can set this parameter to True if you want to keep focus on the field that is in error. Alternatively, you can set the Cancel parameter to False (the default) if you want to allow the end-user to continue entering data without immediately correcting the problem.You may want to use the Validate event without using the Cancel parameter. If an error occurs during validation, you can set the field’s Forecolor property to red and modify the ToolTipText property to display the specific error message for that field. That tells the user something is wrong without interrupting the data entry flow.
Bureaucrat, administrator
16,192
edits