0

I have an issue with getting a property to be shown in a DataGridComboBoxColumn. However, when selecting a value from this combobox, the setter will be updated and the database will change when saved. (So basically its working UI -> Model, but I dont think Model -> UI..)

Basically I have a DataGridComboBoxColumn that is bounded to a Enum. Here is the XAML of where I think the issue lies.

<DataGrid x:Name="dgProductItem" 
          ItemsSource="{Binding ProductVersion.ProductItems}"

<DataGridComboBoxColumn Header="Deployment Type" 
        SelectedItemBinding="{Binding DeploymentType, Mode=TwoWay}"
        SelectedValuePath="DeploymentType" Width="120">

And here is the rest of the code for the DataGridComboBoxColumn

<DataGridComboBoxColumn.ElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource"
                Value="{Binding Source={StaticResource DeploymentTypeEnum}}"/>
        <Setter Property="HorizontalAlignment" Value="Center"></Setter>
    </Style>
</DataGridComboBoxColumn.ElementStyle>


<DataGridComboBoxColumn.EditingElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource"
                Value="{Binding Source={StaticResource DeploymentTypeEnum}}"/>
    </Style>
</DataGridComboBoxColumn.EditingElementStyle>

But as I say, when a user selects a value from the combo box, the setter will be updated so I don't think its too far off.

Here is the property code.

public DeploymentType DeploymentType
{
    get
    {
        return m_DeploymentType;
    }

    set
    {
        m_DeploymentType = value
        PropertyChanged("DeploymentType")
    }
}

Any help would be useful.

Thanks

user3428422
  • 4,300
  • 12
  • 55
  • 119
  • Apologises for the duplication. Answer is in: http://stackoverflow.com/questions/23290946/wpf-datagridtemplatecolumn-combobox-updating-all-rows?noredirect=1#comment35652307_23290946 – user3428422 Apr 28 '14 at 06:47

1 Answers1

0

To get the list you should have a way to pull from the enum type

XAML

Set this at resource level:

    <ObjectDataProvider x:Key="DeploymentTypeEnum" MethodName="GetValues"
                        ObjectType="{x:Type System:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:DeploymentType"/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

Don't forget to add the correct namespaces also in the xaml

         xmlns:local="clr-namespace:ProjectNamespace"
         xmlns:System="clr-namespace:System;assembly=mscorlib"
Lucas Locatelli
  • 356
  • 5
  • 12
  • Hi Lucas, I have this code already (I can get the enum types bounded to the combobox) but I just need the type from the database to be bounded to the combobox. But i think its just picking up the default or 1st enum at the moment – user3428422 Apr 24 '14 at 23:13
  • You are saying that the value when you set in DeploymentType in not coming into the DataGrid? – Lucas Locatelli Apr 25 '14 at 18:00
  • Hi Lucas, that exacly what was happenin, but I got it work now so will post answer. – user3428422 Apr 28 '14 at 06:43