The following example creates a list box. An array serves as the source of the items that appear in the list box items, and the name of the array is specified using the RowSource property. The RowSourceType property is set to 5 (array) to specify that an array is the source for the items in the list box.
The MultiSelect property for the list box is set to True (.T.), making it possible for you to make multiple selections from the list box. The item or items you choose in the list box are displayed by using the ListCount, Selected, and List properties to determine the number of items in the list box and the items you chose.
CLEAR
DIMENSION gaMyListArray(10)
FOR gnCount = 1 to 10 && Fill the array with letters
STORE REPLICATE(CHR(gnCount+64),6) TO gaMyListArray(gnCount)
NEXT
frmMyForm = CREATEOBJECT('Form') && Create a form.
frmMyForm.Closable = .f. && Disable window context menu.
frmMyForm.Move(150,10) && Move the form.
frmMyForm.AddObject('cmbCommand1','cmdMyCmdBtn') && Add "Quit" command button.
frmMyForm.AddObject('lstListBox1','lstMyListBox') && Add ListBox control.
frmMyForm.lstListBox1.RowSourceType = 5 && Specifies an array.
frmMyForm.lstListBox1.RowSource = 'gaMyListArray' && Specifies array source containing list box items.
frmMyForm.cmbCommand1.Visible =.T. && "Quit" command button visible.
frmMyForm.lstListBox1.Visible =.T. && List box visible.
frmMyForm.SHOW && Display form.
READ EVENTS && Start event processing.
DEFINE CLASS cmdMyCmdBtn AS CommandButton && Create command button.
Caption = '\<Quit' && Assign caption on the command button.
Cancel = .T. && Assign default Cancel command button (Esc).
Left = 125 && Command button column.
Top = 210 && Command button row.
Height = 25 && Command button height.
PROCEDURE Click
CLEAR EVENTS && Stop event processing and close form.
CLEAR && Clear main Visual FoxPro window.
ENDDEFINE
DEFINE CLASS lstMyListBox AS ListBox && Create ListBox control.
Left = 10 && List Box column
Top = 10 && List Box row
MultiSelect = .T. && Allow selecting more than 1 item.
PROCEDURE Click
ACTIVATE SCREEN
CLEAR
? "Selected items:"
? "---------------"
FOR nCnt = 1 TO ThisForm.lstListBox1.ListCount
IF ThisForm.lstListBox1.Selected(nCnt) && Is item selected?
? SPACE(5) + ThisForm.lstListBox1.List(nCnt) && Show item.
ENDIF
ENDFOR
ENDDEFINE