SriyahKantha
SriyahKantha

Reputation: 25

multiselect ,autocomplete combobox in wpf

I was able to acheive a multiselect combobox using checkboxes.but that doesnt help if the items in the combobox are more than 600,as the user need to go through all the items in combobox to select.So I wanted to add AutoComplete feature too.But was wondering if thats possible in wpf.Please suggest.Thanks in advance.

Upvotes: 1

Views: 1938

Answers (1)

almulo
almulo

Reputation: 4978

Without knowing exactly how you're populating your Combo and making multiselection work, this should at least serve as an example of how to enable text search and autocompletion:

    <ComboBox IsEditable="True" StaysOpenOnEdit="True" IsTextSearchEnabled="True">
        <ComboBoxItem TextSearch.Text="Thing">
            <ComboBoxItem.Content>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <CheckBox Grid.Column="0" />
                    <TextBlock Grid.Column="1" Text="Thing" />
                </Grid>
            </ComboBoxItem.Content>
        </ComboBoxItem>
        <ComboBoxItem TextSearch.Text="Stuff">
            <ComboBoxItem.Content>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <CheckBox Grid.Column="0" />
                    <TextBlock Grid.Column="1" Text="Stuff" />
                </Grid>
            </ComboBoxItem.Content>
        </ComboBoxItem>
    </ComboBox>

By using TextSearch.Text (or TextSearch.TextPath) you can define the text you want the Combo to use for searching, filtering and autocompleting user input.

By setting IsEditable="True", you allow the user to enter text and do text searchs. With StaysOpenOnEdit="True" the user will be able to see the item he's looking for, and click its CheckBox if needed. And finally IsTextSearchEnabled="True" enables text search, obviously.

Upvotes: 1

Related Questions