I'm testing the xamDataGrid in a precursor to puchasing the product and what I am trying to do is to bind data to the grid based on object collections implemented by generic lists. Having said this, I only see the parent list in the grid whilst I'm expecting to see the child data appear, do I have to specify a relationship in which to display the child table?. My code is as below.
class Order { private int orderId; public int OrderId { get { return orderId; } set { orderId = value; } } private string orderAmount; public string OrderAmount { get { return orderAmount; } set { orderAmount = value; } } private DateTime orderDate; public DateTime OrderDate { get { return orderDate; } set { orderDate = value; } } private List<OrderDetail> orderDetails = new List<OrderDetail>(); internal List<OrderDetail> OrderDetails { get { return orderDetails; } set { orderDetails = value; } } public Order(int orderId, string orderAmount, DateTime orderDate) { this.OrderId = orderId; this.OrderAmount = orderAmount; this.OrderDate = orderDate; } }
class OrderDetail { private string productName; public string ProductName { get { return productName; } set { productName = value; } } private int quantity; public int Quantity { get { return quantity; } set { quantity = value; } } private string unitCost; public string UnitCost { get { return unitCost; } set { unitCost = value; } } public OrderDetail(string productName, int quantity, string unitCost) { this.productName = productName; this.quantity = quantity; this.unitCost = unitCost; } }
Window.xaml.cs ============
Order order1 = new Order(1234, "12.23", DateTime.Now); order1.OrderDetails.Add(new OrderDetail("a", 11, "1.23")); order1.OrderDetails.Add(new OrderDetail("b", 4, "0.03")); orders.Add(order1); Order order2 = new Order(5986, "72.13", DateTime.Now); order2.OrderDetails.Add(new OrderDetail("Z", 38, "71.23")); order2.OrderDetails.Add(new OrderDetail("r", 41, "1.48")); orders.Add(order2); Order order3 = new Order(8431, "2.3", DateTime.Now); order3.OrderDetails.Add(new OrderDetail("aD", 110, "5.11")); order3.OrderDetails.Add(new OrderDetail("bq", 49, "0.83")); orders.Add(order3); Order order4 = new Order(6584, "38.11", DateTime.Now); order4.OrderDetails.Add(new OrderDetail("a", 121, "1.23")); order4.OrderDetails.Add(new OrderDetail("r", 8, "0.03")); orders.Add(order4); Order order5 = new Order(7713, "62.34", DateTime.Now); order5.OrderDetails.Add(new OrderDetail("Z", 89, "1.23")); order5.OrderDetails.Add(new OrderDetail("b", 2, "0.03")); orders.Add(order5); Order order6 = new Order(9566, "1.58", DateTime.Now); order6.OrderDetails.Add(new OrderDetail("a", 1, "1.23")); order6.OrderDetails.Add(new OrderDetail("Z", 84, "0.03")); orders.Add(order6); xamDataGrid1.DataSource = orders;
Window.xaml===========
<Window x:Class="GridTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" xmlns:igDP="http://infragistics.com/DataPresenter"> <Grid> <igDP:XamDataGrid DockPanel.Dock="Top" Name="xamDataGrid1" AutoFit="True" /> </Grid></Window>
Hi,
I have another issue about hierarchical data. Just set an example with the order and orderdetail above .
If the OrderDetails list in the Order has no item when the grid is firstly shown, there will be no sub items shown up which of course is correct. But when OrderDetails are added to the list after that, there will still no sub items shown.
My case need show only the orders at first and then get order details according to differen situation.
I used ObservableCollection<T> for the list and implemented the INotifyPropertyChanged to notify the grid that the data is changed.
sorry my mistake I didn't notice that I had that as internal.... public works a treat. Thanks
It shouldn't require explicit relation definitions. It figures out the relationship by reading Properties that are IEnumerable.
Have you tried making your OrderDetails property public?