How to Fill a Combo Box with a Unique List of ItemsID: Q136640 The information in this article applies to:
SUMMARYTo have a combo box display unique values from a field of a database that contains multiple occurrences of each of those values, use the DisplayValue property in combination with the ListIndex property of the combo box.
MORE INFORMATIONPlacing a string in the combo box DisplayValue property automatically sets the combo box ListIndex property to zero (0) if no match is found or to the index position of a matching string within the created list. Therefore, you can loop through until the ListIndex property is 0, and then add the new list item by using the AddItem method. By using a SCAN...ENDSCAN looping structure, you can create a completely unique list as the following example code illustrates.
Sample CodePlace the following code in the combo box Init event to create a unique list of the <field name> contents before displaying the combo box:
If a new item is typed into the combo box, it must be verified as unique
before being added to the current list. To force the ListIndex property to
change automatically, add the following code to the Valid event procedure
of the combo box:
The code assigns the DisplayValue property to the Value property for the
combo box. Then it checks the value of ListIndex. If ListIndex is 0, the
item is added as before. When this comparison is made, the DisplayValue
property loses its contents, so the Value property is reassigned to the
DisplayValue property in the IF...ENDIF structure.
Additional reference words: 3.00 VFoxWin KBCategory: kbtool kbcode KBSubcategory: FxtoolFormdes |
Last Reviewed: September 13, 1995 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |