Parameter | Description |
---|---|
iStartAt | The position to start the search (0-based and should be 0 to start at the beginning) |
sCaption | The text to search for in the combo list |
If a match is found, returns index of the match, else -1. If iStartAt is higher than the current number of items in the list, returns -1.
Function ComboFindItem Integer iStartAt String sCaption Returns Integer
Call: | Get ComboFindItem iStartAt sCaption to IntegerVariable |
ComboFindItem searches the items in the combo for a match of sCaption starting the search at index position iStartAt.
The search is case-sensitive.
If a match is found, the index position within ComboData is returned.
Object oDBColumnTypeColumn is a cCJGridColumn Set psCaption to "Type" Set piWidth to 59 Set pbComboButton to True Set pbComboEntryState to False Send ComboAddItem "Int" 0 Send ComboAddItem "Char" 2 Send ComboAddItem "DateTime" 3 Send ComboAddItem "Number" 4 Send ComboAddItem "Binary" 5 Send ComboAddItem "Overlap" 6 Send ComboAddItem "Text" 7 End_Object // Somewhere else in the dialog containing a grid with this column Procedure OnClick Integer eType Get ComboFindItem of oDBColumnTypeColumn 0 "Number" to eType End_Procedure
A number of items could be retrieved via ComboData as in:
tComboItem[] MyComboValues Get ComboData to MyComboValues Move (SizeOfArray (MyComboValues) - 1) to iEnd : Function OnValidating Returns Boolean Boolean bError String sType Integer iElement Forward Get OnValidating to bError If (not (bError)) Begin Get SelectedRowValue to sType Get ComboFindItem 0 sType to iElement Move (iElement = -1) to bError End Function_Return bError End_Function
For a case-insensitive search, you could do the following:
Function OnValidating Returns Boolean Boolean bError bFound String sType tComboItemData[] tColumnTypes Integer iElements Forward Get OnValidating to bError If (not (bError)) Begin Get SelectedRowValue to sType Move (Lowercase (sType)) to sType Get ComboData to tColumnTypes Move (SizeOfArray (tColumnTypes)) to iElements Move False to bFound While (iElements > 0 and (not (bFound))) Decrement iElements If (Lowercase (tColumnTypes[iElements].sCaption) = sType) Begin Move True to bFound End Loop Move (not (bFound)) to bError End Function_Return bError End_Function