Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Displaying Hierarchial data using generic lists
posted

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>