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
490
Binding to a collection which holds multiple other collections
posted

I have a xamdatagrid binding to a collection of “Nodes”. Here are my custom classes

    public class Node

    {

        string name = string.Empty;

        public string Name { get; set; }
 

        ObservableCollection<Node> child = new ObservableCollection<Node>();

        public ObservableCollection<Node> Child

        {

            get

            {

                if (child == null) child = new ObservableCollection<Node>();

                return child;

            }

            set { child = value; }

        }

 

        ObservableCollection<Forecast> forecasts = new ObservableCollection<Forecast>();

        public ObservableCollection<Forecast> Forecasts

        {

            get { return forecasts; }

            set { forecasts = value; }

        }

    }

 

    public class Forecast
    {
        public string Name { get; set; }
        public List<Load> Loads { get; set; }
    }
 
    public class Load
    {
        public string Name { get; set; }
        public int Value { get; set; }
    }

I would like to bind my grid to a collection of Nodes. I have to generate my fields dynamically. I first create a field for my Node and Child. Then once I try to expand a child that doesn’t have any other children I would like to display the values in my forecasts collection.

        private void xamDataGrid_RecordExpanding(object sender, Infragistics.Windows.DataPresenter.Events.RecordExpandingEventArgs e)
        {
            if (e.Record.HasChildren == false)
            {
                Field forecast = new Field();
                forecast.Name = "Forecasts";
                forecast.Label = "Region";     
                e.Record.FieldLayout.Fields.Add(forecast);   
            }
        }

When I do this I get 2 blank rows with just the names of the Child field and Forecasts field. If I expand the Forecasts row I can then see the values in my forecasts collection.

Is there a way to display the Forecasts values automatically and not display the Child Field name? I tried to remove the Child field but if I do that I lose all child fields in the grid and can only see my top level node…

Thanks