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 List<Load> Loads { get; set; }
public class Load
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
HI,
Maybe the best thing to do is to show the forecast colleciton when the child collection has no items in it.
I am attaching a sample, which hides the forecast colleciton if the child collection has data and shows the forecast colleciton when the child colleciton has no data.
Please review my sample.
Sincerely,
Matt
Developer Support Engineer
Hi Matt,
Thanks for the quick reply. This is very close to what I’m trying to do only I would like to see the forecast data automatically shown if there are no children, rather than seeing the 2 empty rows (Child and Forecast) and having to expand the Forecast row to see the values. Is this possible?
Thanks,
Chad