• No results found

Using the u_lvs ListView control

In document pfcug (Page 151-156)

The u_lvs ListView control makes it easy for you to display and update database data in a ListView. U_lvs includes services that you enable to obtain the features you need:

Base service Provides find functionality and other basic services Data source service Controls the display and update of database data in

a ListView. Also controls the bitmaps displayed with ListView data Sort service Provides column-header sort functionality (report view

only)

The u_lv ListView control

PFC also includes u_lv, a non-service-based ListView that includes many of the same features as u_lvs. U_lv was the PFC ListView control in previous releases and is not documented here.

Displaying database

data in a ListView You use the ListView data source service to associate a ListView with a data source (not to be confused with an ODBC data source). A data source can be: • DataWindow object (using either data retrieved from the database or data

stored with the DataWindow object) • SQL statement

• DataWindow control • DataStore control

Using standard visual user objects

• Rows from an array • A file

The ListView data source service (implemented through the

n_cst_lvsrv_datasource custom class user object) maintains the ListView’s data source in a DataStore and uses it to populate the ListView. You can also specify which columns from the DataWindow object should display when the ListView is in Report view.

v To establish the initial ListView display: 1 Add a u_lvs user object to the window.

2 Enable the ListView data source service (this example also enables the ListView sort service):

this.of_SetDataSource(TRUE) this.of_SetSort(TRUE)

3 Call the n_cst_lvsrv_datasource of_Register function. This example specifies the DataWindow object, Transaction object, and label column (this example is from a ListView Constructor event):

this.inv_datasource.of_Register("emp_lname", & "d_emplist", SQLCA)

The ListView data source service uses the DataWindow caching service to maintain the data.

4 (Optional) Specify whether right mouse button support is enabled:

this.of_SetRMBMenu(TRUE)

5 (Optional) Specify additional columns to display in Report view (this example displays all columns) and establish picture information:

this.inv_datasource.of_RegisterReportColumn() this.inv_datasource.of_SetPictureColumn("1")

6 (Optional) Declare the ListView as eligible for update via the logical unit of work service and the w_master pfc_Save process:

this.of_SetUpdateable(TRUE)

7 (Optional) Specify whether PFC asks the user to confirm deletions:

this.inv_datasource.of_SetConfirmOnDelete(TRUE)

8 Retrieve data from the database and add rows to the ListView:

9 Extend the pfc_Retrieve event, adding code that calls the of_Retrieve function, which allows you to specify retrieval arguments:

Any la_args[20]

Return this.of_Retrieve(la_args, ads_data)

Deleting items from

the ListView You can delete items from the ListView, optionally deleting them from the data source and the database.

v To remove items from the ListView, allowing them to remain in the u_lvs DataStore and the database:

1 Enable the ListView’s Delete Items property. 2 Call the PowerScript DeleteItem function:

Integer li_index

li_index = lv_list.SelectedIndex() lv_list.DeleteItem(li_index)

Redisplaying deleted rows

To redisplay all rows in the data source, call the of_Reset function followed by the pfc_Populate event.

v To delete selected items from the ListView and the database: 1 Enable the ListView’s Delete Items property.

2 Call the pfc_Delete event:

lv_1.Event pfc_Delete()

3 Call the logical unit of work service of_Save function to update the database (this example is from a user event defined for the ListView control):

PowerObject lpo_obj[ ] n_tr ltr_obj[ ]

IF NOT IsValid(inv_luw) THEN inv_luw = CREATE n_cst_luw END IF

lpo_obj[1] = this ltr_obj[1] = SQLCA

// Error processing omitted to save space inv_luw.of_Save(lpo_obj, ltr_obj)

Using standard visual user objects

Inserting items into

the ListView You can use a ListView to insert items into the database. But because the ListView control allows updates to the label column only, you cannot add information into all the columns displayed in Report view. To get around this, you need another mechanism (such as a dialog box) to acquire enough information to update the DataWindow, the ListView, and the database.

v To insert a row into the database using a ListView:

1 Create a mechanism (such as a dialog box) that collects information needed to add a new row.

2 Use the information you gathered to call the of_InsertItem function. This example assumes you added information to a temporary DataStore, which is used as input to of_InsertItem:

lv_dept.of_InsertItem(ids_newrow, 1)

Using pictures ListViews allow you to specify up to three different pictures to display with an item:

Default picture An image that appears with a Listview item State picture An image that appears to the left of the original image Overlay picture An image (typically an icon or cursor) that appears on

top of a ListView item’s original image, indicating a difference between the ListView item and other items

U_lvs allows you to set up the initial picture display using the following: Picture index Each index entry points to a bitmap file or PowerBuilder

system bitmap that the ListView uses for picture display. You define entries in the picture index using the ListView’s property sheet. This approach results in all ListView items displaying the same picture DataWindow column A column specifying row-specific display

information. The column can come directly from the database or can be a DataWindow computed column. It can contain either of the following: • A string specifying the name of a bitmap file that the ListView uses

when displaying the corresponding row

• An integer specifying the picture index the ListView uses when displaying the corresponding row

Using a DataWindow column allows you to customize ListView item display.

v To use the picture index to specify ListView pictures:

1 Establish the picture index using the ListView’s property sheet. 2 Enable the ListView data source service:

this.of_SetDataSource(TRUE)

3 Specify the appropriate picture index entries by calling n_cst_lvsrv_datasource functions, passing the picture index:

this.inv_datasource.of_SetPictureColumn('1')

this.inv_datasource.of_SetOverlayPictureColumn('1') this.inv_datasource.of_SetStatePictureColumn('1')

v To use DataWindow columns to specify ListView pictures:

1 Establish database or DataWindow columns and populate them with bitmap names (String or Character data type) or picture index specifications (Integer data type).

2 Enable the ListView data source service:

this.of_SetDataSource(TRUE)

3 Specify the appropriate pictures by calling n_cst_lvsrv_datasource functions, passing the DataWindow column names:

this.inv_datasource.of_SetPictureColumn & ('picture_name') this.inv_datasource.of_SetOverlayPictureColumn & ('picture_overlay') this.inv_datasource.of_SetStatePictureColumn & ('picture_state')

Bitmaps must exist

The files named in the retrieved rows must exist in a directory accessible to the application.

Using standard visual user objects

In document pfcug (Page 151-156)