North
North

Reputation: 109

search a ComboBox without accepting new values

This comboBox has a long list of values in it, so I want users to be able to type in what theyre thinking so it will match their text with comboBox values.

Using IsTextSearchable on its own doesn't do anything - adding IsEditable allows it to be searched like I want, but allows the user to enter their own value into the text area, which my form cannot accept.

<ComboBox x:Name="deptCombo" IsEditable="True" IsTextSearchEnabled="True" />

How can I allow users to search the comboBox but remove whatever they entered into the box if its not one of the preexisting items, once they click out of the box (onto another box or the "Enter" button, whatever)?

Upvotes: 4

Views: 633

Answers (1)

Harald Coppoolse
Harald Coppoolse

Reputation: 30512

From your description I assume you want the AutoComplete feature from a ComboBox. So while the operator is typing characters you want to show items in your combobox that match the already typed characters, giving the operator the possibility to select one without having to type the complete value.

I'm not sure how this is done using wpf and Xaml, but the ComboBox class has two properties that control AutoComplete:

 ComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
 ComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;

Now while the operator is typing, the program searches the combo box items and shows the matching ones.

Read the information about these properties to read about other possibilties. MSDN ComboBox.AutoCompleteMode

Upvotes: 1

Related Questions