Description
Occurs when a field has been modified, the field loses focus (for example, the user presses Enter, Tab, or an arrow key or clicks the mouse on another field in the DataWindow), and the data in the field does not pass the validation rules for its column. ItemError can also occur when a value imported into a DataWindow control or DataStore does not pass the validation rules for its column.
PowerBuilder event information
Event ID: pbm_dwnitemvalidationerror
Argument |
Description |
---|---|
row |
Long by value. The number of the row containing the item whose new value has failed validation. |
dwo |
DWObject by value. A reference to the column containing the item. Dwo is a reference to the column control, not the name of the column. |
data |
String by value. The new data the user specified for the item. |
Return Values
Set the return code to affect the outcome of the event:
0 -- (Default) Reject the data value and show an error message box
1 -- Reject the data value with no message box
2 -- Accept the data value
3 -- Reject the data value but allow focus to change
For information on setting the return code in a particular environment, see About return values for DataWindow events.
Usage
If the return code is 0 or 1 (rejecting the data), the field with the incorrect data regains the focus.
The ItemError event occurs instead of the ItemChanged event when the new data value fails a validation rule. You can force the ItemError event to occur by rejecting the value in the ItemChanged event.
Obsolete techniques in PowerBuilder
Information provided by the GetText and GetRow methods is now available in the data and row arguments.
Instead of calling GetColumnName, use the dwo argument and a reference to its Name property.
Instead of calling SetActionCode, use a RETURN statement with the return codes listed above.
Examples
The following excerpt from an ItemError event script of a DataWindow control allows the user to blank out a column and move to the next column. For columns with datatypes other than string, the user cannot leave the value empty (the empty string does not match the datatype). If the user tried to leave the value blank, this code sets the value of the column to a null value of the appropriate datatype.
string ls_colname, ls_datatype ls_colname = dwo.Name ls_datatype = dwo.ColType // Reject the value if non-blank IF Trim(data) <> "" THEN RETURN 0 END IF // Set value to null if blank CHOOSE CASE ls_datatype CASE "long" integer null_num SetNull(null_num) This.SetItem(row, ls_colname, null_num) RETURN 3 CASE "date" date null_date SetNull(null_date) This.SetItem(row, ls_colname, null_date) RETURN 3 // Additional cases for other datatypes END CHOOSE
See also