次の方法で共有


RowSourceType Property

Specifies the type of source for the values in a control. Available at design time and run time.

Control.RowSourceType[ = nSource]

Property Values

  • nSource
    The settings for the RowSourceType property are:

    Setting Description
    0 (Default) None. When the default value is used, fill the list at run time using the AddItem or AddListItem method.
    1 Value. Populated by a comma-delimited list.
    2 Alias. Use the ColumnCount property to select fields in the table.
    3 SQL Statement. A SQL SELECT command that creates a cursor or a table.
    4 Query (.qpr). Specify a file name with a .qpr extension.
    5 Array. Set the columns property to display multiple dimensions.
    6 Fields. A comma delimited list of fields. The fields may be prefaced by the table alias and a period.
    7 Files. List is populated from the current directory. Specify file skeleton (such as *.dbf or *.txt) or mask in the RowSource property.
    8 Structure. Fields from the table specified in RowSource.

    Note that when RowSourceType is set to 8, if the RowSource property is empty the currently selected table is used as the source of the values in a ComboBox or ListBox control. Otherwise, the RowSource property specifies the alias of the table, the name of the table, or the name of the database used as the source of the values in a ComboBox or ListBox control.

    9 Pop-up. Included for backward compatibility.

    For more information about using each of the RowSourceType settings, see Application of List Boxes and Drop-Down List Boxes.

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

RowSource Property

Applies To: ComboBox | ListBox