title: How to bind WPF datagrid to a property in a contained ObservableCollection
body: <p>I am fairly new to C# and WPF so any help will be much appreciated.</p>
  
  <p><strong>UPDATE:</strong>
  I have two objects, PurchaseOrder (PO) and PurchaseOrderDetails (POD).
  PO contains an ObservableCollection of POD.</p>
  
  <p>I am able to get all data needed from my database. 
  So when the OfficeAdmin window loads , I get all Purchase Orders from the database table and display it in the PO datagrid, when a selection is made in the dgPurchaseOrder, the details of the current Purchase Order is displayed in the dgPODescription.  </p>
  
  <p>However i would like to display the 'PODate' property of POD in dgPurchaseOrders, I took a look at the link @Default provided in the comments but I'm still not getting the binding to work, what am I missing? </p>
  
  <pre><code> public class PurchaseOrder : INotifyPropertyChanged
  {
      int _id;
      string _customerName;
      int _customerId;
  
      int _purchaseOrderNumber;  
      int _purchaseOrderDetailsId;
  
  
      private ObservableCollection&lt;Customer&gt; _customer;
      private ObservableCollection&lt;PurchaseOrderDetails&gt; _purchaseOrderDetails;
      public ObservableCollection&lt;Customer&gt; Customer
      {
          get { return _customer; }
          set
          {
              _customer = value;
              OnPropertyChanged("Customer");
          }
      }
      public PurchaseOrder()
      {
          _customerName = String.Empty;
      }
      public int Id
      {
          get { return _id; }
          set
          {
              _id = value;
              OnPropertyChanged("Id");
          }
      }
  
      public string CustomerName
      {
          get { return _customerName; }
          set
          {
              _customerName = value;
              OnPropertyChanged("CustomerName");
          }
      }
      public int CustomerId
      {
          get { return _customerId; }
          set
          {
              _customerId = value;
              OnPropertyChanged("CustomerId");
          }
      }
      public int PurchaseOrderId
      {
          get { return _purchaseOrderDetailsId; }
          set
          {
              _purchaseOrderDetailsId = value;
              OnPropertyChanged("PurchaseOrderDetailsId");
          }
      }
      public int PurchaseOrderNumber
      {
          get { return _purchaseOrderNumber; }
          set
          {
              _purchaseOrderNumber = value;
              OnPropertyChanged("PurchaseOrderDetailsId");
          }
      }
      public ObservableCollection&lt;PurchaseOrderDetails&gt; PurchaseOrderDetails
      {
          get { return _purchaseOrderDetails; }
          set
          {
              _purchaseOrderDetails = value;
              OnPropertyChanged("PurchaseOrderDetails");
          }
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged(string property)
      {
          if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(property));
      }
  }
   public class PurchaseOrderDetails : INotifyPropertyChanged
  {
      int _id;
      int _orderNumber;
      string _customerName;
      int _costPrice;
      int _quantity;
      int _totalAmount;
      int _vat;
      string _date;
      string _deliveryDate;
      int _productId;
      string _productName;
  
      public PurchaseOrderDetails()
      {
          _customerName = string.Empty;
          _productName = string.Empty;
  
  
      }
      public int Id
      {
          get { return _id; }
          set
          {
              _id = value;
              OnPropertyChanged("Id");
          }
      }
      public int OrderNumber
      {
          get { return _orderNumber; }
          set
          {
              _orderNumber = value;
              OnPropertyChanged("Quantity");
          }
      }
      public string CustomerName
      {
          get { return _customerName; }
          set
          {
              _customerName = value;
              OnPropertyChanged("CustomerName");
          }
      }
      public string PODate
      {
          get { return _date; }
          set
          {
              _date = value;
              OnPropertyChanged("PODate");
          }
      }
      public string DeliveryDate
      {
          get { return _deliveryDate; }
          set
          {
              _deliveryDate = value;
              OnPropertyChanged("DeliveryDate");
          }
      }
      public int ProductId
      {
          get { return  _productId;  }
          set
          {
              _productId = value;
              OnPropertyChanged("ProductId");
          }
      }
  
      public string ProductName
      {
          get { return _productName; }
          set
          {
              _productName = value;
              OnPropertyChanged("ProductName");
          }
      }
      public int CostPrice
      {
          get { return _costPrice; }
          set
          {
              _costPrice = value;
              OnPropertyChanged("CostPrice");
          }
      }
      public int Quantity
      {
          get { return _quantity; }
          set
          {
              _quantity = value;
              OnPropertyChanged("Quantity");
          }
      }
      public int Vat
      {
          get { return _vat; }
          set
          {
              _vat = value;
              OnPropertyChanged("Vat");
          }
      }
      public int TotalAmount
      {
          get { return _totalAmount; }
          set
          {
              _totalAmount = value;
              OnPropertyChanged("TotalAmount");
          }
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged(string property)
      {
          if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(property));
      } 
  }
  </code></pre>
  
  <p><strong>OfficeAdmin.xaml</strong></p>
  
  <pre><code>&lt;DataGrid x:Name="dgPurchaseOrder"                             
                                Style="{StaticResource AdminGridStyle}" 
                                     SelectionChanged="dgPurchaseOrder_SelectionChanged"
                                    MouseUp="dgPurchaseOrder_MouseUp"&gt;
  
                              &lt;DataGrid.Columns&gt;
                                  &lt;DataGridTextColumn x:Name="dgPOCustomerName"
                                                  Header="Customer Name" 
                                                  Binding="{Binding CustomerName}" 
                                                  Width="1*" /&gt;
  
                                  &lt;DataGridTextColumn x:Name="PoPurchaseOrderNumber"
                                                  Header="Order Number" 
                                                  Binding="{Binding PurchaseOrderNumber}" 
                                                  Width="1*" /&gt;
  
  
                                  &lt;DataGridTemplateColumn Header="Date"&gt;
                                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                                          &lt;DataTemplate&gt;
                                              &lt;TextBlock Text="{Binding PurchaseOrderDetails.PODate}"/&gt;
  
                                          &lt;/DataTemplate&gt;
                                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                                  &lt;/DataGridTemplateColumn&gt;
                              &lt;/DataGrid.Columns&gt;
  
                          &lt;/DataGrid&gt;
   &lt;DataGrid x:Name="dgPODescription" 
                                    Style="{StaticResource AdminGridStyle}" 
                                    ItemsSource="{Binding PurchaseOrderDetails}"&gt;
  
                              &lt;DataGrid.Columns&gt;
                                  &lt;DataGridTextColumn x:Name="PoProduct"
                                                  Header="Product"                                                     
                                                  Binding="{Binding ProductName}" 
                                                  Width="1*" /&gt;
  
                                  &lt;DataGridTextColumn x:Name="PoQuantity"
                                                  Header="Quantity" 
                                                  Binding="{Binding Quantity}" 
                                                  Width="1*" /&gt;
  
                                  &lt;DataGridTextColumn x:Name="PoCostPrice"
                                                  Header="Cost Price" 
                                                  Binding="{Binding CostPrice}" 
                                                  Width="1*" /&gt;
  
  
                                  &lt;DataGridTextColumn x:Name="PoTotalAmount" 
                                                  Header="Total Amount" 
                                                  Binding="{Binding TotalAmount}" 
                                                  Width="1*" /&gt;
  
                                  &lt;DataGridTextColumn x:Name="PoVat"
                                                  Header="Vat" 
                                                  Binding="{Binding Vat}" 
                                                  Width="1*" /&gt;
  
                                  &lt;DataGridTextColumn x:Name="PoDate"
                                                  Header="Date" 
                                                  Binding="{Binding PODate}" 
                                                  Width="1*" /&gt;
  
                                  &lt;DataGridTextColumn x:Name="DeliveryDate"
                                                  Header="Delivery Date" 
                                                  Binding="{Binding DeliveryDate}" 
                                                  Width="1*" /&gt;
  
  
                              &lt;/DataGrid.Columns&gt;
                          &lt;/DataGrid&gt;
  </code></pre>
  
  <p><strong>OfficeAdmin.xaml.cs</strong></p>
  
  <pre><code>private void Window_Loaded(object sender, RoutedEventArgs e)
      {  
          dgPurchaseOrder.ItemsSource = vm.getAllPurchasOrders();
          dgPurchaseOrder.SelectedIndex = 0;
          dgPODescription.ItemsSource = vm.PurchaseOrderDetails; 
      } 
  private void dgPurchaseOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
          var purchaseOrder = dgPurchaseOrder.SelectedItem as PurchaseOrder;
          if(purchaseOrder!=null)vm.setCurrentPurchaseOrder(purchaseOrder);
          dgPODescription.ItemsSource = vm.PurchaseOrderDetails;
      }
  </code></pre>
  
  <p><strong>vmOfficeAdmin.cs</strong></p>
  
  <pre><code>public ObservableCollection&lt;PurchaseOrder&gt; PurchaseOrder { get; set; }
      public ObservableCollection&lt;Customer&gt; PurchaseOrderCustomer { get; set;}   
      public ObservableCollection&lt;PurchaseOrderDetails&gt; PurchaseOrderDetails {get; set; }
      public PurchaseOrder CurrentPurchaseOrder { get; set; }
  public vmUserManagement()
      {        
          CurrentPurchaseOrder = new PurchaseOrder();
          PurchaseOrder = new ObservableCollection&lt;PurchaseOrder&gt;();
          PurchaseOrderCustomer = new ObservableCollection&lt;Customer&gt;();
          PurchaseOrderDetails = new ObservableCollection&lt;PurchaseOrderDetails&gt;();           
      }                                                                  
  
  
  public ObservableCollection&lt;PurchaseOrder&gt; getAllPurchasOrders()
      {
         PurchaseOrder = RepoDapper.getAllPurchaseOrders();           
         return PurchaseOrder;
      }
  public void setCurrentPurchaseOrder(PurchaseOrder purchaseOrder)
      {            
          CurrentPurchaseOrder = purchaseOrder;
          PurchaseOrderDetails.Clear();
          CurrentPurchaseOrder.PurchaseOrderDetails = RepoDapper.getPurchaseOrderDetails(CurrentPurchaseOrder.Id);
          CurrentPurchaseOrder.Customer = RepoDapper.getPurchaseOrderCustomerDetails(CurrentPurchaseOrder.CustomerId); 
  
  
          foreach (var b in CurrentPurchaseOrder.PurchaseOrderDetails)
          {
              PurchaseOrderDetails.Add(b);
          }
  
          foreach(var d in CurrentPurchaseOrder.Customer)
          {
              PurchaseOrderCustomer.Add(d);
          }
      }
  </code></pre>