FirstElement, NumberOfElements
These properties mimic one of the coolest (and most underused) features of FoxPro 2.x. When a combo or list box is based on an array, you can control which column of the array and which sequence of rows appear.
Usage |
oObject.FirstElement = nFirstElementToShow nFirstElementToShow = oObject.FirstElement oObject.NumberOfElements = nNumberToShow nNumberToShow = oObject.NumberOfElements |
Example |
* This example sets up a combo to show last names * of Employees. It can be set to show only those from * a specified Country. * This code goes in the form's Load and assumes * you've added a property to the form aEmp[1]. * It creates an array of Employees ordered by country. SELECT Employee_Id, First_Name, Last_Name, Country ; FROM Employee ; ORDER BY Country ; INTO ARRAY ThisForm.aEmp * Now set a combo's properties in the combo's Init as follows * to show only the last name column (or make equivalent * settings in the property sheet): This.RowSourceType = 5 This.RowSource = "ThisForm.aEmp" This.FirstElement=3 * In a method on the form, you can change * the combo to include only Employees from a * specified Country (cCountry), as follows: LOCAL nFirst, nFirstRow, nCount nFirst = ASCAN(ThisForm.aEmp, cCountry) nFirstRow = ASUBSCRIPT(ThisForm.aEmp, nFirst, 1) IF nFirst > 0 nCount = 1 DO WHILE nFirstRow + nCount <= ALEN(ThisForm.aEmp,1) ; AND ThisForm.aEmp[nFirstRow + nCount, 4] = cCountry nCount=nCount+1 ENDDO ENDIF * Now set combo properties. * FirstElement is first occurrence of cCountry - 1 * to get last name ThisForm.cboEmps.FirstElement = nFirst-1 ThisForm.cboEmps.NumberOfElements = nCount |
See Also |
ACopy(), AddItem, ColumnCount, ColumnWidths, ComboBox, ListBox, RowSource, RowSourceType |