0

In the below sample, I try to bind the PartNumber to load into DataGridComboBoxColumn, but I couldn't able to do it. How can I do this?

public class Order
{
    public string OrderName { get; set; }
    public List<Parts> PartsList { get; set; }
}

public class Parts
{
    public string PartName { get; set; }
    public double PartQuantity { get; set; }
    public string PartNumber { get; set; }
}

XAML:

<DataGrid Name="dgrStavke"
          AutoGenerateColumns="False"
          Height="160"
          Width="600"
          HorizontalAlignment="Left"
          Margin="5"
          Grid.Row="7"
          Grid.ColumnSpan="4"
          ItemsSource="{Binding}">
  <DataGrid.Columns>
    <DataGridComboBoxColumn Header="ValueCombo"
                            ItemsSource="{Binding Path=PartsList}"
                            DisplayMemberPath="PartNumber">
  </DataGrid.Columns>
</DataGrid>
Daniel
  • 10,864
  • 22
  • 84
  • 115
Smaug
  • 2,625
  • 5
  • 28
  • 44

1 Answers1

0

Use ObservableCollection instead of List .If you want to use list then you will have to notify it. But the best way is to use ObservableCollection. I hope this will help.

I just have seen that ItemSource of ComboBox is also not correct it should be like

ItemsSource="{Binding Path=Order.PartsList}"
yo chauhan
  • 12,079
  • 4
  • 39
  • 58
  • He will . If He will use Add,Remove,Insert,Delete methods of List to add,remove items then nothing will be notified or he will have to notify it explicitly after these methods. It will be notified only if he will assign the value to list using = operator – yo chauhan Jan 22 '13 at 14:56