Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
560
XamComboEditor.ItemsSource updating.
posted

I'm using a XamComboEditor in a XamDataGrid's field.  I added a ValueChanged event handler to react when the user picks a new value.  In some cases, I show another window, in which I modify the combo's ItemsSource data.  When new data is entered in that window, I set the value of the XamComboEditor to the item that was added.  With my current code, the Value is displayed correctly, but the ItemsSource is not showing the new item in the combo's list.

How do you make the displayed list in synch with the underlying ItemsSource?

Here's my ValueChanged handler:

    private void CmbDrug_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)

    {

      if (e.NewValue != null)

      {

        int newValue = int.Parse(e.NewValue.ToString());

        if (newValue ==NewDrugItemId) //Magic value that triggers the new Window

        {

          PickNewDrugView pndv = new PickNewDrugView(pndvm); //This is my window that will add items to the ViewModel.DrugList.Model

          if (pndv.Prompt()) //ShowDialog like

          {

            ViewModel.DrugList.Model.Add(pndvm.SelectedDrug); //this adds a new Item to the list

//this is to update the ItemsSource property

            ((XamComboEditor)sender).ItemsSource = null;

            ((XamComboEditor)sender).ItemsSource = ViewModel.DrugList.Model;

            ((XamComboEditor)sender).Value = pndvm.SelectedDrug.Id; // Active item is the new one

          }

        }       

      }

    }