locked
Combobox: Type to Jump to Value

    Question

  • Hi,

    I have a simple combobox that has each of the states in it. I would like the user to be able to type on the keyboard and automatically jump to the corresponding state value (just like in a web form). How can I achieve this? 

    I'm attempting to do this using XAML and C# in Visual Studio 2013.

    Here is the code I'm using:

    <ComboBox x:Name="SiteStateDrpdn" HorizontalAlignment="Left" Margin="560,202,0,0" Grid.Row="1" VerticalAlignment="Top" Width="179" Height="37" PlaceholderText="State..." FontFamily="{StaticResource ButtonFont}" FontSize="{StaticResource DefaultFontSize}" SelectionChanged="SiteValidator_SelectionChanged">
                <x:String>Alabama</x:String>
                <x:String>Alaska</x:String>
                <x:String>Arizona</x:String>
                <x:String>Arkansas</x:String>
                <x:String>California</x:String>
                <x:String>Colorado</x:String>
                <x:String>Connecticut</x:String>
                <x:String>Delaware</x:String>
                <x:String>District of Colombia</x:String>
                <x:String>Florida</x:String>
                <x:String>Georgia</x:String>
                <x:String>Hawaii</x:String>
                <x:String>Idaho</x:String>
                <x:String>Illinois</x:String>
                <x:String>Indiana</x:String>
                <x:String>Iowa</x:String>
                <x:String>Kansas</x:String>
                <x:String>Kentucky</x:String>
                <x:String>Louisiana</x:String>
                <x:String>Maine</x:String>
                <x:String>Maryland</x:String>
                <x:String>Massachusetts</x:String>
                <x:String>Michigan</x:String>
                <x:String>Minnesota</x:String>
                <x:String>Mississippi</x:String>
                <x:String>Missouri</x:String>
                <x:String>Montana</x:String>
                <x:String>Nebraska</x:String>
                <x:String>Nevada</x:String>
                <x:String>New Hampshire</x:String>
                <x:String>New Jersey</x:String>
                <x:String>New Mexico</x:String>
                <x:String>New York</x:String>
                <x:String>North Carolina</x:String>
                <x:String>North Dakota</x:String>
                <x:String>Ohio</x:String>
                <x:String>Oklahoma</x:String>
                <x:String>Oregon</x:String>
                <x:String>Pennsylvania</x:String>
                <x:String>Rhode Island</x:String>
                <x:String>South Carolina</x:String>
                <x:String>South Dakota</x:String>
                <x:String>Tennessee</x:String>
                <x:String>Texas</x:String>
                <x:String>Utah</x:String>
                <x:String>Vermont</x:String>
                <x:String>Virginia</x:String>
                <x:String>Washington</x:String>
                <x:String>West Virginia</x:String>
                <x:String>Wisconsin</x:String>
                <x:String>Wyoming</x:String>
            </ComboBox>

    Thanks for your help!


    • Edited by JB-CI-IRS Tuesday, July 15, 2014 7:32 PM
    Tuesday, July 15, 2014 7:31 PM

Answers

  • That's not standard behaviour so you'll need to implement it yourself.

    You can listen for character events and then set the selection accordingly. It's probably easier if you databind and then search or filter the backing collection than flitting through the hard-coded items.

    There are also several 3rd party implementations of autocomplete boxes which may work for you. I'm not sure if any do drop-downs or only textboxes though.

    --Rob


    Tuesday, July 15, 2014 8:18 PM
    Owner