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
I am attaching a new sample that addresses your additional requirements.
Matt Developer Support Engineer
Please let me know if you need further assistance regarding this case.
I am attaching a new sample.
Sincerley,
The sample solution doesn’t solve our problem. The solution does not solve the issue when a Child (or Node) only has a Forecast collection and no other Children. I am running into problems only showing the forecast values or only showing the Children values.
Please see the screenshot below of what I’m trying to achieve. Note that Node 2 only contains children Nodes and Node 3 only contains a collection of Forecast values. Also, a children is capable of holding either other children nodes (see Node 1, Child2.2) or a collection of Forecasts (Node 3, Child 2.2.1, Child 2.3). All children values will be a sum it’s Forecast values and since a Forecast is the lowest level the Forecast rows would not be expandable.