SetText method (DataWindows)
Description
Replaces the text in the edit control over the current row
and column in a DataWindow control or DataStore.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataStore object |
Web ActiveX |
DataWindow control |
Syntax
[PowerBuilder]
1 |
integer <span>dwcontrol</span>.<span>SetText</span> ( string <span>text </span>) |
[Web ActiveX]
1 |
number <span>dwcontrol</span>.<span>SetText</span> ( string <span>text</span> ) |
Argument |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or |
text |
A string whose value you want to put |
Return Values
Returns 1 if it succeeds and –1 if an error occurs.
If any argument’s value is null, in PowerBuilder and JavaScript
the method returns null.
Usage
SetText only sets the value in the edit control. When the
user changes focus to another row and column, PowerBuilder accepts
the text as the item in the row and column.
Using SetText in the ItemChanged and ItemError events
In the ItemChanged or ItemError event, PowerBuilder or your
own script might determine that the value in the edit control is
invalid or that it needs further processing. You can call SetItem to
specify a new item value for the row and column.
If you want the user to have an opportunity to enter a different
value, after calling SetItem you can call SetText to
put that same value in the edit control so that the user sees the
value too. You can also call SetText without calling SetItem.
In the script, use a return code that rejects the value in the edit
control, avoiding further processing, but does not allow the focus
to change. To retain focus and display an error message, return
1 for ItemChanged or 0 for ItemError.
When you use a return code that rejects the data the user
entered but allows the focus to change (a return code of 2 in the
script for the ItemChanged event or 3 in the ItemError event), you
do not need to call SetText because the value
set with SetItem displays when the focus changes.
Examples
These statements replace the value of the current
row and column in dw_employee with Tex and then call AcceptText to
accept and move Tex into the current column. (Do not use this code
in the ItemChanged or ItemError event because it calls AcceptText.)
1 |
dw_employee.<span>SetText</span>("Tex") |
1 |
dw_employee.AcceptText() |
This example converts a number that the user enters
in the column called credit to a negative value and sets both the
item and the edit control’s text to the negative number.
This code is the script for the ItemChanged event. The data argument
holds the newly entered value:
1 |
integer negative |
1 |
1 |
IF dwo.Name = "credit" THEN |
1 |
IF Integer(data) > 0 THEN |
1 |
// Convert to negative if it's positive |
1 |
negative = Integer(data) * -1 |
1 |
1 |
// Change the primary buffer value. |
1 |
This.SetItem(row, "credit", negative) |
1 |
1 |
// Change the value in the edit control |
1 |
This<span>.SetText</span>(String(negative)) |
1 |
RETURN 1 |
1 |
END IF |
1 |
END IF |