Collection as Rowsource in Listbox

Here’s some sample code for a new feature in VFP9: the Listbox Rowsource can be a collection, and can even specify collection members for multiple columns:

CLEAR ALL

CLEAR

PUBLIC ox as form

PUBLIC oc as Collection

USE HOME()+"\samples\data\customer"

oc=NEWOBJECT("collection")

#define USEOLE 1

#if USEOLE

#define NUM 4

DIMENSION ofrm[NUM]

FOR i = 1 TO 4

            ofrm[i]=NEWOBJECT("form")

            ofrm[i].caption="cap"+TRANSFORM(i)

ENDFOR

FOR EACH xx IN _vfp.Forms

            oc.Add(xx)

endfor

 

#else

oc.Add("start")

SCAN NEXT 10

            SCATTER NAME orec

            oc.Add(orec)

ENDSCAN

#endif

oc.Add("end")

ox=NEWOBJECT("form")

ox.Left=300

ox.visible=1

ox.AllowOutput=.f.

IF .f.

            ox.addobject("lst","combobox")

ELSE

            ox.addobject("lst","listbox")

ENDIF

ox.lst.visible=1

ox.lst.width=300

ox.lsT.RowSourceType=10

ox.lst.columncount=2

ox.lst.columnwidths="100,100"

#if USEOLE

oc=_vfp.Forms

ox.lsT.RowSource="oc,caption,visible"

#else

*oc=_vfp

?EVALUATE("oc")

ox.lsT.RowSource="oc,company,contact" &&,cust_id,company"

*ox.lsT.RowSource="oc,cust_id,company"

 

#endif