0

I have a editable dropdown combobox, every thing works fine. But i want that it should show only show the matching items. For example if i type 'A' in it should show items starting with alphabet A.

Below is my Combobox code.

<ComboBox Height="23" HorizontalAlignment="Left" Margin="331,65,0,0" Name="comboBox2" VerticalAlignment="Top" Width="163" IsEditable="True" IsTextSearchEnabled="True" PreviewTextInput="ComboBox_PreviewTextInput"/>

Here is Binding source for Combobox

public void BindComboBox2(ComboBox comboBox2)
    {

        SqlDataAdapter da = new SqlDataAdapter("Select p_id_pk,p_name,fk_com_id FROM products ", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "products");
        comboBox2.ItemsSource = ds.Tables[0].DefaultView;
        comboBox2.DisplayMemberPath = ds.Tables[0].Columns["p_name"].ToString();
        comboBox2.SelectedValuePath = ds.Tables[0].Columns["p_id_pk"].ToString();
        selected_company = ds.Tables[0].Columns["fk_com_id"].ToString();


    }

And here it PreviewTextInput Handler Code

private void ComboBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
        ComboBox comboBox = sender as ComboBox;
        comboBox.IsDropDownOpen = true;
    }
yaseen enterprises
  • 141
  • 1
  • 1
  • 8
  • For sake please don't say its duplicate mine logic is different i am fetching data from Database, The question which you referred to contains simple enumerable list data. And am not using MVVM. So please stop doing this. – yaseen enterprises Aug 01 '18 at 10:08
  • 1
    Your `ComboBox ItemsSource` is a `List` it doesn't matter where it came from, it's just a list of objects. So this should work for you https://stackoverflow.com/questions/34382459/simple-wpf-combobox-filter .Before being so salty, try what people told you. – Juan Carlos Rodriguez Aug 01 '18 at 10:49

0 Answers0