0
Xaml:無法弄清楚如何綁定包含一個或多個記錄的第二個DataGrid。使用EntityFramework在DataGrid中綁定DataGrid
<DataGrid Name="lstPurchaseDataGrid" Visibility="Visible" AutoGenerateColumns="False" Margin="20,0,20,0" IsReadOnly="True" materialDesign:DataGridAssist.CellPadding="4 2 2 2" materialDesign:DataGridAssist.ColumnHeaderPadding="4 2 2 2" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="Purchase Id" Width="100" Binding="{Binding ID}"/>
<DataGridTextColumn Header="Vendor Name" Width="2*" Binding="{Binding Vendor.Name}"/>
<DataGridTextColumn Header="Parts Amount" Width="100" Binding="{Binding SubTotal}"/>
<DataGridTextColumn Header="Discount" Width="100" Binding="{Binding Discount}"/>
<DataGridTextColumn Header="Total Amount" Width="120" Binding="{Binding GrandTotal}"/>
<DataGridTextColumn Header="Purchase Date" Width="100" Binding="{Binding PurchaseDate, StringFormat=d}" />
<DataGridTextColumn Header="Created On" Width="100" Binding="{Binding CreatedOn}" />
<DataGridTextColumn Header="Status" Width="100" Binding="{Binding Status}" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid AutoGenerateColumns="False" x:Name="lstDetailsDataGrid" IsReadOnly="False" ItemsSource="{Binding PurchaseInfoes}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Id}" Header="Part Id" />
<DataGridTextColumn Binding="{Binding Path=Part.PartNo}" Header="Part No" />
<DataGridTextColumn Binding="{Binding Path=Part.Name}" Header="Name" />
<DataGridTextColumn Binding="{Binding Path=Quantity}" Header="Quantity" />
<DataGridTextColumn Binding="{Binding Path=CGST}" Header="CGST" />
<DataGridTextColumn Binding="{Binding Path=SGST}" Header="SGST" />
<DataGridTextColumn Binding="{Binding Path=Discount}" Header="Discount" />
<DataGridTextColumn Binding="{Binding Path=Total}" Header="Total" />
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
C# lstPurchaseDataGrid.Items.Clear();
var purchaseList = (from purchases in dt.Purchases.Include("Vendor")
select purchases).ToList();
lstPurchaseDataGrid.ItemsSource = purchaseList;
C#訂購類代碼
公共部分類訂購 { [System.Diagnostics.CodeAnalysis.SuppressMessage( 「Microsoft.Usage」, 「CA2214:DoNotCallOverridableMethodsInConstructors」)] 公共購買() {this.PurchaseInfoes = new HashSet(); this.PurchasePayDetails = new HashSet(); }
public int ID { get; set; }
public int VendorID { get; set; }
public decimal SubTotal { get; set; }
public decimal Discount { get; set; }
public decimal GrandTotal { get; set; }
public string Status { get; set; }
public System.DateTime PurchaseDate { get; set; }
public string InvoiceNo { get; set; }
public string Note { get; set; }
public System.DateTime CreatedOn { get; set; }
public string CreatedBy { get; set; }
public Nullable<System.DateTime> UpdatedOn { get; set; }
public string UpdatedBy { get; set; }
public Nullable<decimal> RemainingPayment { get; set; }
public virtual Vendor Vendor { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PurchaseInfo> PurchaseInfoes { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PurchasePayDetail> PurchasePayDetails { get; set; }
}
也許你需要急於購買的負載,以及'dt.Purchases.Include (「Vendor」)。Include(「PurchaseInfoes」)'。我認爲目前它們在查詢後爲空purchaseList – ASh
var purchaseList =(從dt.Purchases.Include中的購買(「Vendor」).include(「PurchaseInfoes」) 選擇購買).ToList();仍然不工作..! –