-3

Hello all I have a combo box with check box and text box to search the results, what I am trying to do is when user search for specific records it should match and display which is working fine. When user check that check box and try to search again I would like to preserve the previous item which was checked along with the new search

enter image description here

enter image description here

enter image description here

I have my code here

https://drive.google.com/open?id=0ByVjmdncQgagX28zbkRWMVhPdVg3Q3EyYVVOcjkxcE0xWlNJ

This is related to the post here the same code WPF ComboBox with checkboxes and textbox with search field

Learner
  • 351
  • 7
  • 25
  • 4
    gathering your code from all around the internet would not be an easy thing to do! It would be better if you post the code along with your question instead of making it more difficult for us to find it. – Bizhan Aug 16 '18 at 10:54
  • I have tried few things but didn't work the code is same as in the previous post – Learner Aug 16 '18 at 10:57
  • there are many codes in the previous post. which one are you referring to? we can't guess everything. – Bizhan Aug 16 '18 at 11:00
  • The code I shared in the google drive has the full source – Learner Aug 16 '18 at 11:28

1 Answers1

0

You need to update method multiCombo_TextChange and handle selected and searched items to be your new data source as the following:

private void multiCombo_TextChange(object sender, EventArgs e)
    {
        TextBox textBox = sender as TextBox;
        Dictionary<string, int> searchedItem = new Dictionary<string, int>(); 
        searchedItem = (GetFacility(data, textBox.Text));
        Dictionary<string, int> selectedItems = new Dictionary<string, int>();
        Dictionary<string, int> allItems = new Dictionary<string, int>();
        foreach (var item in searchedItem)
        {
            allItems.Add(item.Key, item.Value);
        }
        //multiCombo.SelectedItems.Clear();
        foreach (var selectedItem in multiCombo.SelectedItems)
        {

            selectedItems.Add(selectedItem.Key, selectedItem.Value);
        }


        foreach (var select in selectedItems)
        {
            if (!allItems.ContainsKey(select.Key))
            {
                allItems.Add(select.Key, select.Value);
            }
        }
        multiCombo.ItemsSource = allItems;
        foreach (var selected in selectedItems)
        {
            if (!multiCombo.SelectedItems.ContainsKey(selected.Key))
            {
                multiCombo.SelectedItems.Add(selected.Key, selected.Value);
            }

        }

    }
Muhammad Hassan
  • 475
  • 2
  • 14