Setting DataWindow data with a DataWindow data expression – PB Docs 126

Setting DataWindow data with a DataWindow data expression

When you set data in a DataWindow control, the datatypes of
the source values must match the datatypes of the columns being
set.

Single value or an array

When your data expression refers to a single row and column,
you can set the value in the DataWindow control with a value that
matches the column’s datatype. When you are setting values
in a single column and specifying an expression that can refer to
multiple rows, the values you assign must be in an array of the
appropriate datatype.

Multiple columns and whole rows

When the expression refers to more than one column, you can
assign the data with a structure or user object to the DataWindow
data. When you create the definition, the fields (in a structure)
or instance variables (in a user object) must match the columns.
There must be the same number of fields or variables, defined in
the same order as the columns, with compatible datatypes.

When your expression can refer to multiple rows, you need
an array of the structure or user object.

Using arrays to set values

You do not have to know in advance how many rows are involved
when you are setting data in the DataWindow control. PowerBuilder
uses the number of elements in the source array and the number of
rows in the target expression to determine how to make the assignment
and whether it is necessary to insert rows.

If the target expression is selected rows or a range
of rows
, then:

  • When
    there are more array elements than target rows,
    the extra array elements are ignored

  • When there are fewer array
    elements than target rows, the column(s) in the extra target rows
    are filled with default values

If the target expression is all rows but not all
columns
, then:

  • When
    there are more array elements than target rows,
    the extra array elements are ignored

  • When there are fewer array
    elements than target rows, only the first rows up to the number
    of array elements are affected

If the target expression is all rows and all columns,
then the source data replaces all the existing rows, resetting the
DataWindow control to the new data.

Inserting new rows

When you are setting data and you specify a range, then if
rows do not exist in that range, rows are inserted to fill the range.
For example, if the DataWindow control has four rows and your expression
says to assign data to rows 8 through 12, then eight more rows are
added to the DataWindow control. The new rows use the initial default
values set up for each column. After the rows are inserted, the
array of source data is applied to the rows as described above.

Examples

These examples refer to a DataWindow object that has three
columns: emp_id, emp_lname, and salary. The window
declares these arrays as instance variables and the window’s
Open event assigns four elements to each array:

The uo_empdata user object has three instance variables:
id, name, and salary. The uo_empid_name user object
has two instance variables: id and name.

This example sets emp_lname in the selected rows
to the values of is_name, an array with four elements.
If two rows are selected, only the first two values of the array
are used. If six rows are selected, the last two rows of the selection are
set to an empty string:

This example sets salary in rows 8 to 12 to the values in
the array id_salary. The id_salary array has only
four elements, so the extra row in the range is set to 0 or a default
value:

This statement resets the DataWindow control and inserts four
rows to match the array elements of iuo_data:

This example sets columns 1 and 2 in rows 5 to 8 to the values
in the array iuo_id:

This example sets emp_id in the first four rows to
the values in the ii_id array. Rows 5 through 12 are not
affected:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x