Aracılığıyla paylaş


List Property

A character string array used to access the items in a ComboBox or ListBox control. Not available at design time; read/write at run time.

Control.List(nRow [, nCol]])[ = cChar]

Return Value

  • nRow
    Specifies the row of the item to be retrieved using the display order. For example, nRow = 3 specifies the third row shown in the list.

  • nCol
    Specifies the column of the item to be retrieved using the display order. For example, nCol = 2 specifies the second column shown in the list. If nCol is not specified, the List property retrieves the first column by default. Specify nCol only for ComboBox and ListBox controls that have more than one column.

  • cChar
    Specifies a value to add to a combo box or list box.

Remarks

The List property works in conjunction with the ListCount property; enumerating a list from 1 to ListCount returns all items in the list.

You cannot use array functions with the List property. However, if you set the RowSourceType property to 5 (Array) and set the RowSource property to the array of values to be contained in the list, you can use array functions on the array specified in the RowSource property.

Note

When RowSourceType is set to 0 or 1, add items to a combo box or list box using the AddItem method. To remove items, use the RemoveItem method. To keep items in alphabetic order, set the control's Sorted property to true (.T.) before adding items to the list.

Example

Applies To: ComboBox Control | ListBox Control

In the following example, ListCount is used to cycle through all the of the items specified by the List property of the combo box or list box.

The following example creates a list box. The source of the items that appear in the list box items is an array; the array is specified with the RowSourceType and RowSource properties.

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 ListCount property is used within a FOR ... ENDFOR loop to display the item or items you choose in the list box. The Selected property is used to determine the items you chose, and the List property is used to return the items.

CLEAR

DIMENSION gaMyListArray(10)
FOR gnCount = 1 to 10  && Fill the array with letters
   STORE REPLICATE(CHR(gnCount+64),6) TO gaMyListArray(gnCount)
ENDFOR

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .F.  && Disable the Control menu box 

frmMyForm.Move(150,10)  && Move the form

* Add "Quit" command button and list box control
frmMyForm.AddObject('cmbCommand1','cmdMyCmdBtn')
frmMyForm.AddObject('lstListBox1','lstMyListBox')

* && Specifies an array containing listbox items
frmMyForm.lstListBox1.RowSourceType = 5
frmMyForm.lstListBox1.RowSource = 'gaMyListArray'

frmMyForm.cmbCommand1.Visible =.T.  && "Quit" Command button visible
frmMyForm.lstListBox1.Visible =.T.  && "List Box visible

frmMyForm.SHOW  && Display the form
READ EVENTS  && Start event processing

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && 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, 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

See Also

Reference

AddItem Method (Visual FoxPro)

IndexToItemID Method

ItemIDToIndex Method

ListCount Property

ListItem Property

ListItemID Property

RowSource Property

RowSourceType Property

Sorted Property

Other Resources

Properties (Visual FoxPro)

Language Reference (Visual FoxPro)