RowSource Property
Specifies the source of the values in a ComboBox or ListBox control. Read/write at design time and run time.
Note
The RowSourceType property determines the source you can set for the RowSource property. It is recommended that you set RowSourceType before setting RowSource. For more information, see RowSourceType Property.
Control.RowSource [= cValue]
Return Value
cValue
Specifies the source for the values displayed in the control.Note
When you set the RowSource property using code, you must enclose the value with quotation marks ("").
The following table lists possible values for cValue.
cValue
Description
Nothing
The control is filled at run time using the AddItem or AddListItem method or List or ListItem properties. (Default)
For more information, see AddItem Method, AddListItem Method, List Property, and ListItem Property.
Val1,Val2,Val3,...
A comma-delimited list of values.
The control is populated with values from the comma-delimited list.
TableAlias
The alias of an open table.
The control is populated with values from the fields in the table.
SQLSELECTStatement
A SQL SELECT statement that creates a cursor or table, for example, "SELECT * FROM Table".
The control is populated with values from columns in the cursor or table created by the SQL statement.
Note
A browse window appears when the SQL SELECT statement is executed.
MyQueryFile.qpr
The name of a query (.qpr) file.
> [!NOTE] > <P>Be sure to include the .qpr file name extension. A Browse window appears when the query is executed.</P> <p>The control is populated with values from the columns in the query results.</p></td> </tr> <tr class="even"> <td><p>myArray</p></td> <td><p>The name of an array.</p> <p>The control is populated with values from the array.</p></td> </tr> <tr class="odd"> <td><p>TableAlias.Field1, Field2, Field3, ...</p></td> <td><p>A comma-delimited list of fields from a single open table, which can be prefaced by the table alias and a period.</p> <p>The control is populated with values from the fields. The <strong>ColumnCount</strong> property should match the number of fields specified.</p></td> </tr> <tr class="even"> <td><p>*.fileExt</p></td> <td><p>A file skeleton (for example, "*.dbf" or "*.txt") or a mask.</p> <p>The control is populated with file names from the current directory as well as options to choose a different drive or directory containing the file names.</p></td> </tr> <tr class="odd"> <td><p>TableName or TableAlias</p></td> <td><p>The name or alias of a table.</p> <p>The control is populated with field names from the table.</p> > [!NOTE] > <P>When <STRONG>RowSourceType</STRONG> is set to 8, and if <STRONG>RowSource</STRONG> property is empty, the control is populated with field names from the currently selected table. Otherwise, if <STRONG>RowSource</STRONG> specifies the name of a table, a table alias, or the name of the database, the control is populated with field names from the specified source.</P>
MenuName
The name of a menu. Included for backward compatibility.
CollectionName [, CollectionMemberProp [, CollectionMemberProp2 [, ...]]]
CollectionName specifies a string that is an expression, which evaluates to a Visual FoxPro or COM Collection object.
You can also specify properties of objects in the collection. The control is populated with values of the properties specified as well as with other members of the collection that are not objects.
> [!NOTE] > <P>When you specify a collection and properties of the objects in the collection for <STRONG>RowSource</STRONG>, the value for each property is displayed as a separate column. Members of the collection that are not objects display in the first column.</P> > [!NOTE] > <P>If you do not specify any properties for <STRONG>RowSource</STRONG>, the control displays other members of the collection that are not objects and the string "(Object)" for each object in the collection in a single column. The string "(Object)" is returned for the <STRONG>Value</STRONG> property. For more information, see <A href="5yb2038e(v=vs.90).md">Value Property</A>.</P>
Remarks
Applies To: ComboBox | ListBox
You can display multiple columns in the control by setting the ColumnCount property. The values you specify for RowSource fill the control, by row, up to the number of columns specified by the ColumnCount property. For example, you can display values in multiple columns by setting RowSourceType to 1 (Value) and specifying the values, separated by commas, for each column and row for the RowSource property as shown in the following example:
myListBox.ColumnCount = 2 myListBox.RowSource = "Col1Row1,Col2Row1,Col1Row2,Col2Row2,Col2Row3"
In the example, no value is entered between the value in column 2, row 2 and the value in column 2, row 3 so no value displays in column 1, row 3.
To specify an alias for the table containing the columns, use the following syntax:
myListBox.RowSource = Alias.Col1Row1,Col2Row1,Col1Row2,Col2Row2,Col2Row3
Note
When the ColumnCount property is set to 0 or 1, the control displays the first item or value only in a single column. Otherwise, the control displays each item or value in a column up to the number of columns specified by ColumnCount. You might need to set the ColumnWidths property to expand the width of the control so the items or values within display properly.
For more information, see ColumnCount Property, How to: Create Multicolumn List Boxes, and Display Multiple Columns in a List Box Sample.
Because the default value for the Value property is numeric, if you want the Value property to reflect the character string of the selected item in a list box or combo box, set the Value property to an empty string (""). To enter an empty string in the Properties window, press the SPACEBAR key and then the BACKSPACE key. For more information, see Value Property and Properties Window.
Example
Example 1
The following example creates a list box on a form and specifies an array as the source of the items in the list box. The RowSourceType property is set to 5 (Array) to specify that an array is the source for the items in the list box, and the name of the array is specified by the RowSource property. The MultiSelect property for the list box is set to True (.T.) so that you can make multiple selections from the list box.
The steps performed in this example appear as follows:
Clear the main Visual FoxPro window using the CLEAR command.
Create an array called gaMyListArray using the DIMENSION command.
Fill the array with letters using the FOR...ENDFOR and STORE commands.
Create a form using the CREATEOBJECT( ) function.
Disable the Close button on the form's title bar by setting the Closable property.
Move the form by setting the Move property.
Add a CommandButton control based on the user-defined cmdMyCmdButton class by calling the AddObject method.
Add a ListBox control based on the custom lstMyListBox class by calling the AddObject method.
Specify an array as the row source type for the list box by setting the RowSourceType property.
Specify the array gaMyListArray as the row source for the list box by setting the RowSource property.
Show the command button by setting the Visible property.
Show the list box by setting the Visible property.
Display the form by calling the form's Show method.
Begin event processing by calling the READ EVENTS command.
Define the user-defined cmdMyCmdButton class based on the CommandButton control using the DEFINE CLASS command. The code in the DEFINE CLASS command sets properties for the user-defined class and defines procedures.
Define the user-defined lstMyListBox class based on the ListBox control using the DEFINE CLASS command. The code in the DEFINE CLASS command sets properties for the user-defined class and defines procedures.
CLEAR DIMENSION gaMyListArray(10) FOR gnCount = 1 to 10 STORE REPLICATE(CHR(gnCount+64),6) TO gaMyListArray(gnCount) NEXT frmMyForm = CREATEOBJECT('Form') frmMyForm.Closable = .F. frmMyForm.Move(150,10) frmMyForm.AddObject('cmbCommand1','cmdMyCmdBtn') frmMyForm.AddObject('lstListBox1','lstMyListBox') frmMyForm.lstListBox1.RowSourceType = 5 frmMyForm.lstListBox1.RowSource = 'gaMyListArray' frmMyForm.cmbCommand1.Visible =.T. frmMyForm.lstListBox1.Visible =.T. frmMyForm.Show READ EVENTS DEFINE CLASS cmdMyCmdBtn AS CommandButton Caption = '\<Quit' Cancel = .T. Left = 125 Top = 210 Height = 25 PROCEDURE Click CLEAR EVENTS CLEAR ENDDEFINE DEFINE CLASS lstMyListBox AS ListBox Left = 10 Top = 10 MultiSelect = .T. PROCEDURE Click ACTIVATE SCREEN CLEAR ? "Selected items:" ? "---------------" FOR nCnt = 1 TO ThisForm.lstListBox1.ListCount IF ThisForm.lstListBox1.Selected(nCnt) ? SPACE(5) + ThisForm.lstListBox1.List(nCnt) ENDIF ENDFOR ENDDEFINE
Example 2
The following example explains how to specify a collection for the RowSource property of a list box. Suppose you create a collection referenced by the memory variable oCustomerCol using the following steps:
Call the SCAN...ENDSCAN command with the Customers table in the Northwind sample database located in ...\Samples\Northwind directory.
Call SCATTER...NAME for each record.
Add the object created by the SCATTER command to the collection.
You can specify the collection referenced by oCustomerCol and the record fields for the RowSource property as follows:
lstmyListBox.RowSource = "colCustomerCol, CustID, Company, LastName"
For more examples, see How to: Choose the Type of Data for a List or Combo Box.
See Also
Tasks
How to: Allow Users to Add Items to a List Box
How to: Display Child Records in a List
How to: Populate Query Results in a Form Control
How to: Refresh a One-to-Many Display Based on a List Value
Concepts
Reference
Other Resources