SetValue

Description

Sets the value of an item in a value list or code table for a column in a DataWindow control or DataStore. (A value list is called a code table when it has both display and data values.) SetValue does not affect the data stored in the column.

NoteSetValueByColNum A separate method name is provided as an alternative syntax for the Web DataWindow server component, which cannot use overloaded methods.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control, DataWindowChild object, DataStore object

Web

Server component

Web ActiveX

DataWindow control

Syntax

PowerBuilder

integer dwcontrol.SetValue ( string column, integer index, string value )
integer dwcontrol.SetValue ( integer column, integer index, string value )

Web DataWindow server component

short dwcontrol.SetValue ( string column, short index, string value )
short dwcontrol.SetValueByColNum ( short column, short index, 
	string value )

Web ActiveX

number dwcontrol.SetValue ( string column, number index, string value) 
number dwcontrol.SetValue ( number column, number index, 
	string value) 

Argument

Description

dwcontrol

A reference to a DataWindow control or DataStore.

column

The column that contains the value list or code table. Column can be a column number or a column name.

The edit style of the column can be DropDownListBox, Edit, or RadioButton. SetValue has no effect when column has the EditMask or DropDownDataWindow edit style.

index

The number of the item in the value list or code table for which you want to set the value.

value

A string whose value is the new value for the item. For a code table, use a tab (~t in PowerBuilder) to separate the display value from the data value ("Texas~tTX"). The data value must be a string that can be converted to 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.

Examples

Example 1

This statement sets the value of item 3 in the value list for the column emp_state of dw_employee to Texas:

dw_employee.SetValue("emp_state", 3, "Texas")

Example 2

This statement sets the display value of item 3 in the code table for the column named emp_state of dw_employee to Texas and the data value to TX:

dw_employee.SetValue("emp_state", 3, "Texas~tTX")

Example 3

The following statements use a SQL cursor and FETCH statement to populate the ListBox portion of a DropDownListBox style column called product_col of a DataWindow object with code table values:

integer prod_code, i = 1

string prod_name


DECLARE prodcur CURSOR FOR

		SELECT product.name, product.code

		FROM product USING SQLCA;


CONNECT USING SQLCA;

IF SQLCA.SQLCode <> 0 THEN

		MessageBox("Status","Connect Failed " &

			+ SQLCA.SQLErrText)

		RETURN

END IF


OPEN prodcur;

IF SQLCA.SQLCode <> 0 THEN

		MessageBox("Status","Cursor Open Failed " &

			+ SQLCA.SQLErrText)

		RETURN

END IF


FETCH prodcur INTO :prod_name, :prod_code;


DO WHILE SQLCA.SQLCode = 0

		dw_products.SetValue("product_col", i, &

			prod_name + "~t" + String(prod_code))

		i = i + 1

		FETCH prodcur INTO :prod_name, :prod_code;

LOOP


CLOSE prodcur;

DISCONNECT USING SQLCA;

See also

GetValue