15

How can we enable the free text entry for combo box in WPF? I tried with IsEditable="True", but even that is not working...

my xaml syntax is: <ComboBox SelectedValue="{Binding Path=CountryValue, Mode=TwoWay}" IsEditable="True" ItemsSource="{Binding Path=CountryValues, Mode=OneWay}"></ComboBox>

2
  • You should bind against Text="{Binding CountryValue}". SelectedValue won't work if IsEditable="True".
    – Marcel
    Dec 20, 2018 at 17:09
  • Or bind against SelectedItem if you just use IsEditable to AutoComplete the input in the combobox, so you will get the original object.
    – Momo
    Feb 13, 2019 at 16:38

1 Answer 1

14

Found this on the web: Link

<Window x:Class="LearnWPF.EditableComboBox.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="LearnWPF.EditableComboBox" Height="300" Width="300"
    >
  <Window.Resources>
    <XmlDataProvider x:Key="items" XPath="//item">
      <x:XData>
        <items >
          <item>01</item>
          <item>02</item>
          <item>03</item>
        </items>
      </x:XData>
    </XmlDataProvider>
  </Window.Resources>
    <Grid>
      <ComboBox IsEditable="True" DataContext="{StaticResource items}"
                ItemsSource="{Binding}"/>
    </Grid>
</Window>
5
  • @singla - I copied this code and for me it works fine. the combobox is editable.
    – Christian
    Apr 21, 2011 at 11:00
  • @singla - try copying the code exactly. It really should work. By the way: what error / exception does it give you?
    – Christian
    Apr 21, 2011 at 11:06
  • 2
    @Christian- Actually I have applied the Style on the combobox. And that style was making the combo box readonly. now its working properly. Apr 21, 2011 at 11:30
  • @singla - That makes sense. Styles can override properties of your controls, which makes it hard to find where those properties were set. What is really really helpful in such cases is a tool called Snoop. You can download Snoop from snoopwpf.codeplex.com
    – Christian
    Apr 21, 2011 at 11:34
  • 2
    Link is broken. Feb 1, 2018 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.