To start I would like to explain the title of this sample, as it is really a textbox pretending to be the UI portion of the drop down list and a textbox pretending to be the list portion of drop down list. I am not sure what I would have called the sample but "Drop-Down List Control with auto-complete" and "Searchable Drop-Down List" came from the title of the first two forum posts I tried to answer with this sample. It seems we can't update the entries in a drop down list when the list is open, which is why I have tried to mimic the behaviour with these two controls.
The changes I have made are;
- Display the list when the user enters the field, so the user knows this field is special
- Show some "ghost text", giving instructions to the user
- Sort the values in the list
- Allow for strict scoping
- Allow for keyboard users, previous the sample only worked with the mouse.
To use this in your own form
- Copy the subform DropDownList to you own form
- If you don't want the option to match first characters/match any characters the delete the RadioButtonList under the DropDownList subform. You may need to update the code in the initialise event of DropDownList subform to set the default option, currently it defaults to match first characters.
- Change the null display pattern in the Search textbox, to suit the items you are search over. This is how the "ghost text" is implemented and currently says "'Search by country name".
- Update the code in the change event of the Search textbox, this is where the matching is performed against the list of countries. The format of the countries XML list is;
- <Country>
<Region>Oceania</Region>
<Code>36</Code>
<Name>Australia</Name>
</Country> - So the binding expression for match first characters is;
'$record.Country.[Lower(Left(Name,' + (xfa.event.newText.length) + ')) == "' + xfa.event.newText.toLowerCase() + '"]' - This matches the left characters of the Name element against the characters entered in the Search textbox, xfa.event.newText. A case insensitive match is made by calling toLowerCase() on the xfa.event.newText and calling the FormCalc function Lower on the Name element. I find the using FormCalc in binding expressions to be about four times faster.