SetText

Description

Replaces the text in the edit control over the current row and column in a DataWindow control or DataStore.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control, DataStore object

Web ActiveX

DataWindow control

Syntax

PowerBuilder

integer dwcontrol.SetText ( string text )

Web ActiveX

number dwcontrol.SetText ( string text ) 

Argument

Description

dwcontrol

The name of the DataWindow control or DataStore in which you want to specify the text in the current row and column.

text

A string whose value you want to put in the current row and column. The value must be compatible with the datatype of the column.

Returns

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

Example 1

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.)

dw_employee.SetText("Tex")

dw_employee.AcceptText()

Example 2

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:

integer negative


IF dwo.Name = "credit" THEN

		IF Integer(data) > 0 THEN

			// Convert to negative if it's positive

			negative = Integer(data) * -1


			// Change the primary buffer value.

			This.SetItem(row, "credit", negative)


			// Change the value in the edit control

			This.SetText(String(negative))

			RETURN 1

		END IF

END IF

See also