ItemError event
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 |
|
dwo |
DWObject by value. A reference to the |
|
data |
String by value. The new data the user |
Web ActiveX event information
Event name: onItemError
|
Argument |
Description |
|---|---|
|
Row |
Number. The number of the row containing |
|
Name |
String. The name of the column containing |
|
Data |
String. The new data the user specified |
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.
|
1 |
string ls_colname, ls_datatype |
|
1 |
|
1 |
ls_colname = dwo.Name |
|
1 |
ls_datatype = dwo.ColType |
|
1 |
// Reject the value if non-blank |
|
1 |
IF Trim(data) <> "" THEN |
|
1 |
RETURN 0 |
|
1 |
END IF |
|
1 |
|
1 |
// Set value to null if blank |
|
1 |
CHOOSE CASE ls_datatype |
|
1 |
|
1 |
CASE "long" |
|
1 |
integer null_num |
|
1 |
SetNull(null_num) |
|
1 |
This.SetItem(row, ls_colname, null_num) |
|
1 |
RETURN 3 |
|
1 |
|
1 |
CASE "date" |
|
1 |
date null_date |
|
1 |
SetNull(null_date) |
|
1 |
This.SetItem(row, ls_colname, null_date) |
|
1 |
RETURN 3 |
|
1 |
|
1 |
// Additional cases for other datatypes |
|
1 |
END CHOOSE |