Step 2 Select Data to Fill the List

Visual LANSA

Step 2. Select Data to Fill the List

FRM055 - List Component Basics

In this step you will add code in the form Initialize event to populate the DEPTS combo box.

1.  Your code to add entries from the file DEPTAB to the DEPTS combo box should use the CLR_LIST, SELECT, ADD_ENTRY and ENDSELECT commands.

     SELECT / ENDSELECT is a database I/O command which  reads records based entry sequence, by full key, by partial key or generically for example. Refer to the Technical Guide for further details and examples. Remember you can press F1 on any command in the editor to jump straight to its online guide entry.

     Your code should look like the following:

Evtroutine Handling(#com_owner.Initialize)
Set Com(#com_owner) Caption(*component_desc)
Clr_List Named(#DEPTS)
Select Fields(#DEPTS) From_File(deptab)

Add_Entry To_List(#DEPTS)

Endselect

Endroutine

 

     Note: the combo box definition DEPTS can be used in the SELECT Fields() parameter, to retrieve the fields defined as columns in DEPTS.

2.  Compile and test your form.

     Note: The first entry in the combo box has focus and the fields on the form are populated. When a row in a list component has focus or is selected, the form fields for the list columns are populated.

3.  Click on the drop down button to see all list entries:

     The list is displayed in the sequence that entries were loaded. In this case it is loaded in department code sequence (DEPTMENT). We will look later at how entries in a list can be sorted. In this example one solution could be to add a logical file to the file DEPTAB in DEPTDESC sequence and use this logical file to load the combo box.

     Note: the dropped down view has a scroll bar. The DropDownCount property of the combo box can be changed to display more entries if required. The default value is 8.

4.  Select a different department. Once again note that the form fields are populated from the selected list row.