List Collection Example 2

This example is otherwise the same as the List Collection Example 1 except that the drag and drop operation involves more employee details and these details are stored in an employee object:

The Employee Object

The employee object is used to store employee details. This object is then used in the collection for the drag and drop operation.

The object defines and publishes these employee properties:

Define the Collection

A list collection is created dynamically  to be the payload for this drag operation. It is a list collection of #Employee objects. A #DragEmployee variable is created to store the employee objects to be inserted in the collection. Because the collection is dynamic, a reference is set to it using the SET_REF command:

 

Define_Com Class(#Prim_LCOL<#Employee>) Name(#PayLoadList) Reference(*Dynamic)

Define_Com Class(#Employee) Name(#DragEmployee) Reference(*Dynamic)

Set_Ref Com(#PayLoadList) To(*Create_as #Prim_LCOL<#Employee>)

Add Items to the Collection

A Selectlist loop is used to add the selected employee objects to the list collection. The list collection is then set as the payload for the drag operation:

 

Selectlist Named(#DRAG_LIST)

Continue If('#Drag_List.Currentitem.Selected *ne True')

Set_Ref Com(#DragEmployee) To(*Create_as #Employee)

Set Com(#DragEmployee) Pempno(#Empno) Pgivename(#GiveName) Psurname(#Surname) Psalary(#Salary) Pdepartment(#Deptment) Ppostcode(#PostCode)

Invoke Method(#PayLoadList.Insert) Item(#DragEmployee)

Endselect

Set_Ref Com(#PayLoad) To(#PayLoadList)

Retrieve Items from the Collection

In the DragDrop event of the list on the second form a list collection is defined and the payload containing the collection of selected employees is cast to it.

Define_Com Class(#Prim_LCOL<#Employee>) Name(#EmployeePayLoad) Reference(*Dynamic)

Set_Ref Com(#EmployeePayLoad) To(*Dynamic #PayLoad)

The list collection is iterated through in a For/EndFor loop to retrieve the employee details:

For Each(#EmployeeObject) In(#EmployeePayLoad)

Change Field(#EMPNO) To('#EMPLOYEEOBJECT.PEMPNO')

Change Field(#GIVENAME) To('#EMPLOYEEOBJECT.PGIVENAME')

Change Field(#SURNAME) To('#EMPLOYEEOBJECT.PSURNAME')

Change Field(#POSTCODE) To('#EMPLOYEEOBJECT.PPOSTCODE')

Add_Entry To_List(#DROP_LIST)

Endfor

Source Code for List Collection Example 2

Employee Object

Create the object as a reusable part. In this example it is named #employee.

Function Options(*DIRECT)

Begin_Com Role(*EXTENDS #PRIM_OBJT)

* ----------------------------

* This is an "Employee" object

* ----------------------------

* Define the member variables that define an "Employee" object ....

Define_Com Class(#Empno)

Define_Com Class(#GiveName)

Define_Com Class(#SurName)

Define_Com Class(#Deptment)

Define_Com Class(#Salary)

Define_Com Class(#PostCode)

* Publish the properties that an "Employee" exposes .....

Define_Pty Name(pEmpno) Get(*Auto #Empno) Set(*Auto #Empno)

Define_Pty Name(pGiveName) Get(*Auto #GiveName) Set(*Auto #GiveName)

Define_Pty Name(pSurName) Get(*Auto #SurName) Set(*Auto #SurName)

Define_Pty Name(pDepartment) Get(*Auto #Deptment) Set(*Auto #Deptment)

Define_Pty Name(pSalary) Get(*Auto #Salary) Set(*Auto #Salary)

Define_Pty Name(pPostCode) Get(*Auto #PostCode) Set(*Auto #PostCode)

End_Com

First Form

Function Options(*DIRECT)

Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(319) Clientwidth(509) Dragstyle(Automatic) Height(346) Left(255) Top(111) Width(517)

* The Drag List Definition. Note the use of the DragStyle(Automatic) property

Define_Com Class(#PRIM_LTVW) Name(#DRAG_LIST) Displayposition(1) Dragstyle(Automatic) Fullrowselect(True) Height(285) Left(8) Parent(#COM_OWNER) Tabposition(1) Top(8) Width(465)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_1) Displayposition(1) Parent(#DRAG_LIST) Source(#EMPNO) Width(18)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_2) Displayposition(2) Parent(#DRAG_LIST) Source(#SALARY) Width(20)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_3) Displayposition(3) Parent(#DRAG_LIST) Source(#SURNAME) Width(20)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_4) Displayposition(4) Parent(#DRAG_LIST) Source(#GIVENAME) Width(20)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_5) Displayposition(5) Parent(#DRAG_LIST) Source(#DEPTMENT) Width(11)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_6) Displayposition(6) Parent(#DRAG_LIST) Source(#POSTCODE) Width(20) Widthtype(Remainder)

* Define the drop form (change #LCOL00004 to the name you give to the second form)

Define_Com Class(#LCOL00004)

* ===============================

* Handle main form initialization

* ===============================

Evtroutine Handling(#com_owner.Initialize)

* Fill the drag list with employee details

Select Fields(#DRAG_LIST) From_File(PSLMST)

Add_Entry To_List(#DRAG_LIST)

Endselect

* Show the drop list form (change #LCOL00004 to the name you give to the second form)

Invoke Method(#LCOL00004.ShowForm)

Endroutine

* ==================================

* Handle starting the drag operation

* ==================================

Evtroutine Handling(#Drag_List.StartDrag) Draglist(#DragList) Continue(#Continue) Payload(#PayLoad)

Define_Com Class(#Prim_LCOL<#Employee>) Name(#PayLoadList) Reference(*Dynamic)

Define_Com Class(#Employee) Name(#DragEmployee) Reference(*Dynamic)

* Dynamically create the list collection that is to to be the "payload"

* for this drag operation. It is a list collection of #Employee objects

Set_Ref Com(#PayLoadList) To(*Create_as #Prim_LCOL<#Employee>)

* Now fill the list collection with the employees that are selected

Selectlist Named(#DRAG_LIST)

Continue If('#Drag_List.Currentitem.Selected *ne True')

Set_Ref Com(#DragEmployee) To(*Create_as #Employee)

Set Com(#DragEmployee) Pempno(#Empno) Pgivename(#GiveName) Psurname(#Surname) Psalary(#Salary) Pdepartment(#Deptment) Ppostcode(#PostCode)

Invoke Method(#PayLoadList.Insert) Item(#DragEmployee)

Endselect

* Finished. Set the correct return values

Set Com(#Continue) Value(True)

Set_Ref Com(#PayLoad) To(#PayLoadList)

Set Com(#DragList) Dragliststyle(Selection)

Endroutine

End_Com

Second Form

 

Function Options(*DIRECT)

Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(433) Clientwidth(331) Dragstyle(Automatic) Formstyle(StayOnTopChild) Height(460) Left(453) Top(49) Width(339)

* The Drop List Definition

Define_Com Class(#PRIM_LTVW) Name(#DROP_LIST) Displayposition(1) Dragstyle(Automatic) Fullrowselect(True) Height(418) Left(6) Parent(#COM_OWNER) Tabposition(1) Top(7) Width(321)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_1) Displayposition(1) Parent(#DROP_LIST) Source(#EMPNO) Width(18)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_3) Displayposition(2) Parent(#DROP_LIST) Source(#SURNAME) Width(20)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_4) Displayposition(3) Parent(#DROP_LIST) Source(#GIVENAME) Width(40)

Define_Com Class(#PRIM_LVCL) Name(#LVCL_6) Displayposition(4) Parent(#DROP_LIST) Source(#POSTCODE) Width(20) Widthtype(Remainder)

* ===============================

* Handle Drag Over the drop list

* ===============================

Evtroutine Handling(#Drop_List.DragOver) Acceptdrop(#AcceptDrop) Payload(#PayLoad)

* If the payload to be dropped is a list collection of employees

* then accept it otherwise reject it .....

If_Ref Com(#PayLoad) Is(*Instance_of #Prim_LCol<#Employee>)

Set Com(#AcceptDrop) Value(True)

Else

Set Com(#AcceptDrop) Value(False)

Endif

Endroutine

* =========================================

* Handle the actual drop into the drop list

* =========================================

Evtroutine Handling(#Drop_List.DragDrop) Payload(#PayLoad)

Define_Com Class(#Prim_LCOL<#Employee>) Name(#EmployeePayLoad) Reference(*Dynamic)

* Cast the payload as a list collection of employee objects ....

Set_Ref Com(#EmployeePayLoad) To(*Dynamic #PayLoad)

* Fill drop list with all the employee numbers in the payload ...

Clr_List Named(#DROP_LIST)

For Each(#EmployeeObject) In(#EmployeePayLoad)

Change Field(#EMPNO) To('#EMPLOYEEOBJECT.PEMPNO')

Change Field(#GIVENAME) To('#EMPLOYEEOBJECT.PGIVENAME')

Change Field(#SURNAME) To('#EMPLOYEEOBJECT.PSURNAME')

Change Field(#POSTCODE) To('#EMPLOYEEOBJECT.PPOSTCODE')

Add_Entry To_List(#DROP_LIST)

Endfor

Endroutine

End_Com