Partager via


RowSource Property

Specifies the source of the values in a ComboBox or ListBox control. Available at design time and run time.

Control.RowSource[ = cName]

Property Values

  • cName
    Specifies the source of the values.

Remarks

The source of the values can be a comma-delimited list of values, a table, a SQL statement that creates a cursor or a table, a query, an array, a comma-delimited list of fields (which may be prefaced by a period and the table alias), a file skeleton (such as *.dbf or *.txt), a table's field names, or a menu. Use the RowSourceType property to set the type of row source.

You can use RowSource to specify multiple columns for a ComboBox or ListBox control at design time. To specify multiple columns, set RowSourceType to 1 (Value) and specify the RowSource values (separated by a comma) as follows:

Col1Row1,Col2Row1,Col1Row2,Col2Row2,,Col2Row3

To specify an alias for the table containing the columns, use the following syntax:

Alias.Col1Row1,Col2Row1,Col1Row2,Col2Row2,,Col2Row3

The values you specify fill the control, by row, up to the number of columns that are specified by the ColumnCount property. The preceding example assumes that ColumnCount is set to 2. As shown in the preceding example, there will be no value in column 1, row 3 because there are two successive commas with no value entered between them preceding column 2, row 3.

Example

The following example creates a list box. The source of the items that appear in the list box items is an array; the name of the array is specified with 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.), allowing 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 the Control menu box 

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' && Array containing listbox items

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

ColumnCount Property | RecordSource Property | RowSourceType Property

Applies To: ComboBox | ListBox