Editable ComboBox with value binding not in list

I have an editable combobox where the not always preferred item is in the drop down list.

I would like to be able to manually enter text in a text field that extends to the line associated with SelectedValue.

Currently, a string bound to a SelectedValue is only updated if the entered value is included in ComboBox elements.

How to allow input of custom values ​​that are not available in the ComboBox list, and correctly distribute them to the associated value?

+61
wpf combobox editing
Sep 18 '10 at 19:58
source share
2 answers

I did it yesterday and today, and it looks like this:

  • set the combo box IsEditable="true"

  • instead of binding to SelectedItem , it binds to the Text property in the combo box

  • if you are attached to a custom object, not just strings, you also need to set TextSearch.TextPath="NameOfField" . This allows you to work with text search, and also displays this property in the text box.

In general, I got something like:

 <ComboBox x:Name="c" IsEditable="True" IsTextSearchEnabled="True" IsTextSearchCaseSensitive="False" StaysOpenOnEdit="True" Text="{Binding NameOnViewModel}" TextSearch.TextPath="NameOnChildItems" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource DataTemplate}" /> <TextBlock Text="{Binding ElementName=c,Path=Text}" /> 
+104
Nov 16 '10 at 23:50
source share

It will also be sufficient to set the binding to the Text Combo property.

 <ComboBox IsTextSearchEnabled="True" IsEditable="True" ItemsSource="{Binding Items}" Text="{Binding SelectedItemText, Mode=TwoWay}" /> 
+24
Dec 12 '11 at 11:50
source share



All Articles