how to search and change items in combobox?

mc 3,461 Reputation points

Can I search in the combobox ?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
695 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 80,906 Reputation points

    You can use an ObservableCollection.

    For example :

      <ComboBox x:Name="cmb1" Header="Test ComboBox" Height="60" Width="296" Margin ="100,10,0,0"                          ItemsSource="{x:Bind itemList}"/>
      System.Collections.ObjectModel.ObservableCollection<string> itemList = new System.Collections.ObjectModel.ObservableCollection<string>();

    Fill ComboBox at beginning :

      for (int i = 0; i <= 10; i++)
          itemList.Add("Item " + i.ToString("D2"));

    Test updating an item :

                    string sItemToSearch = "Item 05";
                    string sNewItem = "New Item";
                    int nIndex = itemList.IndexOf(sItemToSearch);
                    if (nIndex != -1)
                        if ((string)cmb1.SelectedItem == sItemToSearch)
                            itemList[nIndex] = sNewItem;
                            cmb1.SelectedItem = itemList[nIndex];
                            itemList[nIndex] = sNewItem;

0 additional answers

Sort by: Most helpful