0

I have implemented a datagrid with some datagrid columns.

One of these columns are a DatagridComboboxColumn. That has itemsource binding to an ObservableCollection list from my Viewmodel.

How do i update the itemsource, so i can see the new list on the UI? The list is changing from the getter, that means I can't use OnPropertyChange. Is there any way around updating the UI From ViewModel or what should be the way to go here?

ViewModel property:

    private ObservableCollection<string> usedHMDGroups = new ObservableCollection<string>();
    private ObservableCollection<string> startHMDGroups = new ObservableCollection<string>{
                "136b6405",
                "136b6406",
                "136b6407",
                "136b6408",
                "136b6409",
                "136b6410",
                "None"
    };
    public ObservableCollection<string> HMDGroups
    {
        get
        {
            ObservableCollection<string> HMDGroupList = new ObservableCollection<string>(startHMDGroups.Except(usedHMDGroups));
            return HMDGroupList;

        }
        set 
        {
            OnPropertyChange("HMDGroups");
            
        }
    }

DatagridComboBoxColumn from datagrid:

                <DataGridComboBoxColumn x:Name="hmdComboCol" Header="HMD Group" 
                                    SelectedValueBinding="{Binding HMDGroup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                    ItemsSource="{Binding Path=HMDGroups, Mode=TwoWay, Source={StaticResource ComboItems}}"/>
  • First of all, it seems pointless to use ObservableCollection, since you apparently never add or remove elements to/from an existing collection instance. Then, to make the PropertyChanged event fire, the property setter has obviously to be called. Otherwise you may call OnPropertyChanged from anywhere else in your view model. The property should then be read-only. – Clemens Jul 02 '20 at 09:13

1 Answers1

0

I found out, that i could just set the itemsource of the column again to the same list. This will use the getter again.

hmdComboCol.ItemsSource = vhitems.HMDGroups;