ShareData

Description

Shares data retrieved by one DataWindow control (or DataStore), which is referred to as the primary DataWindow, with another DataWindow control (or DataStore), referred to as the secondary DataWindow.

The controls do not share formatting; only the data is shared, including data in the primary buffer, the delete buffer, the filter buffer, and the sort order.

NoteIf you are using ShareData and then use ReselectRow on the primary DataWindow, the secondary DataWindow resets back to row 1, column 1.

Applies to

DataWindow type

Method applies to

PowerBuilder

DataWindow control, DataWindowChild object, DataStore object

Web ActiveX

DataWindow control, DataWindowChild object

Syntax

PowerBuilder

integer dwprimary.ShareData ( datawindow dwsecondary )
integer dwprimary.ShareData ( datastore dwsecondary )
integer dwprimary.ShareData ( datawindowchild dwsecondary )

Web ActiveX

number dwprimary.ShareData ( datawindow dwsecondary ) 
number dwprimary.ShareData ( datawindowchild dwsecondary ) 

Argument

Description

dwprimary

The name of the primary DataWindow. The primary DataWindow is the owner of the data. When you destroy this DataWindow, the data disappears. Dwprimary can be a child DataWindow but it cannot be a report in a composite DataWindow object or a Crosstab DataWindow object.

dwsecondary

The name of the secondary DataWindow with which the control dwprimary will share the data. The secondary DataWindow can be a child DataWindow or a report in a composite DataWindow object but it cannot be a Crosstab DataWindow object.

Returns

Returns 1 if it succeeds and –1 if an error occurs.

Usage

The columns must be the same for the DataWindow objects in the primary and secondary DataWindow controls, but the SELECT statements may be different. For example, you could share data between DataWindow objects with these SELECT statements:

SELECT dept_id from dept

SELECT dept_id from dept where dept_id = 200

SELECT dept_id from employee

NoteWHERE clause in secondary has no effect The WHERE clause in the DataWindow object in the secondary DataWindow control has no effect on the number of rows returned. The number of rows returned to both DataWindow controls is determined by the WHERE clause in the primary DataWindow object.

You could also share data with a DataWindow object that has an external data source and columns defined to be like the columns in the primary. To share data between a primary DataWindow and more than one secondary DataWindow control, call ShareData for each secondary DataWindow control.

ShareData shares only the primary buffer of the primary DataWindow with the primary buffer of the secondary DataWindow. A DropDownDataWindow in the secondary DataWindow will not display any data unless you explicitly populate it. You can do this by getting a handle to the DropDownDataWindow (by calling the GetChild method) and either retrieving the DropDownDataWindow or using ShareData to share data from an appropriate data source with the DropDownDataWindow.

To turn off sharing in a primary or secondary DataWindow, call the ShareDataOff method. When sharing is turned off for the primary DataWindow, the secondary DataWindows are disconnected and the data disappears. However, turning off sharing for a secondary DataWindow does not affect the data in the primary DataWindow or other secondary DataWindows.

When you call methods in either the primary or secondary DataWindow that change the data, PowerBuilder applies them to the primary DataWindow control and all secondary DataWindow controls are affected.

For example, when you call any of the following methods for a secondary DataWindow control, PowerBuilder applies it to the primary DataWindow. Therefore, all messages normally associated with the method go to the primary DataWindow control. Such methods include:

There are some restrictions on the use of ShareData:

NoteUse DataSource with RichTextEdit controls To share data between a DataStore or DataWindow and a RichTextEdit control, use the DataSource method.

Examples

Example 1

In this example, the programmer wants to allow the user to view two portions of the same data retrieved from the database and uses the ShareData method to accomplish this in the script for the Open event for the window.

The SELECT statement for both DataWindow objects is the same, but the DataWindow object in dw_dept displays only two of the five columns displayed in dw_employee:

CONNECT USING SQLCA;

dw_employee.SetTransObject(SQLCA)

dw_employee.Retrieve()

dw_employee.ShareData(dw_dept)

Example 2

These statements share data between two DataWindow controls in different sheets within an MDI frame window:

CONNECT USING SQLCA;

mdi_sheet_1.dw_dept.SetTransObject(SQLCA)

mdi_sheet_1.dw_dept.Retrieve()

mdi_sheet_1.dw_dept.ShareData(mdi_sheet_2.dw_dept)

Example 3

This example shares data in a tabular DataWindow with a report in a Composite DataWindow. The name of the report in the Composite DataWindow is dw_1:

DataWindowChild dwreport

// Get a reference to the nested report
dw_composite.GetChild("dw_1", dwreport)
dw_tabular.ShareData(dwreport)

See also