Article ID: 137183
Article Last Modified on 2/19/2002
Property Value ------------------------------------- Style 0 - Dropdown Combo RowSourceType 0 - None RowSource (should be empty) ColumnCount 2 ColumnWidth 50,120 BoundColumn 1 (this is the default)RowSourceType must be set to 0 and RowSource must be empty when items are added to the combo box programmatically.
SET EXACT ON && Comparison done in Valid may be comparing blanks
SELECT orders
DO WHILE recno()<10 && Fill the combo box with the first 10 records
ThisForm.Combo1.AddItem(order_id,This.ListCount+1,1)
ThisForm.Combo1.AddListItem(to_country,This.ListCount,2)
SKIP
ENDDO
This.Value=This.List(1) && Initialize the value of the combo box
ListCount is initially 0 because no items are contained in the list. The
AddItem method places Order_id in column one. ListCount+1 indicates the
first row added. After the AddItem method is called, ListCount is 1. The
AddListItem method adds To_country to column two of row one.
in_list=.F.
IF AT(",",This.DisplayValue)>0
first=ALLTRIM(LEFT(This.DisplayValue,at(",",This.DisplayValue)-1))
second=ALLTRIM(RIGHT(This.DisplayValue,LEN(This.DisplayValue);
-AT(",",This.DisplayValue)))
ELSE
first=ALLTRIM(This.DisplayValue)
ENDIF
FOR I= 1 to This.ListCount
IF ALLTRIM(first)=ALLTRIM(This.List(I))
in_list=.T.
=MESSAGEBOX("Item number is already in list,"+chr(13)+ ;
" item not entered","STOP")
ENDIF
ENDFOR
IF !in_list
IF AT(",",This.DisplayValue)=0
=MESSAGEBOX("Comma followed by description needed,"+chr(13)+ ;
" item not entered","STOP")
ELSE
This.AddItem(first,This.ListCount+1,1)
This.AddListItem(second,This.ListCount,2)
This.Value=""
ENDIF
ENDIF
In the For loop, This.DisplayValue contains the current entry in the
combo box. This.Value has not yet been assigned. If This.DisplayValue is
equal to some value already in the combo box list, In_list is set to
True and the next section of code is not run. If it is not found in
the list, then the entry in the combo box is parsed based on a comma
placed between what would be the columns one and two. The parsed items
are then added to the list by calling the AddItem and AddListitem
methods. This.List(I) contains only the values in column one because
the BoundColumn is 1.
Additional query words: listbox VFoxWin
Keywords: KB137183