I am loading a large datasource into a XamDataGrid and in the FieldLayoutInitialized event handler I'm defining some SummaryDefinition based on Property Attributes.
foreach (var columnDetailsAttribute in attributes.Where(attribute => attribute.TotalsBy || attribute.AverageBy)){ var summaryDefinition = new SummaryDefinition(); summaryDefinition.SourceFieldName = columnDetailsAttribute.PropertyName; summaryDefinition.Calculator = columnDetailsAttribute.TotalsBy ? (SummaryCalculator) Infragistics.Windows.DataPresenter.SummaryCalculator.Sum : Infragistics.Windows.DataPresenter.SummaryCalculator.Average; e.FieldLayout.SummaryDefinitions.Add(summaryDefinition);}
this works fine.
However I would like to turnoff or not define the SummaryDefinition if the grouping only has one group.
Hello ahrensd,
Thank you for your post!
I have been looking into your issue and it seems that I am missing something from your scenario. Would you please provide me with more detailed information about the functionality you are using? Also if possible would you please provide me with small sample application, that shows the functionality you are using?
Having this information would help me further investigate this matter for you.
Looking forward to hearing from you.
Gergana,
I have a IEnumerable<DataType> where the DataType has upto 20 properties. The IEnumerable has between 10 to 1000 items. I'm grouping the data by upto 4 properties of the DataType. This is fine when there is 1000+ items, all the groups make sense. However when there are only 10 items, 2 of the groups are not required. So I would like to examine the groupings and if the group only contains one group, then remove, turn off or set a setting that stops XamDataGrid to not allow groups with only one group.
Sorry just realised that I pasted the wrong code snippet in my original post.
I'm doing it just before I'm doing the summaries with this:
if (attributes.Any(attribute => attribute.GroupBy)){ if (!XamDataGrid.Resources.Contains("ColourKey")) { var datatype = typeof (GroupByRecordPresenter); var style = new Style(datatype); style.Resources.Add(new ComponentResourceKey(typeof (XamDataGrid), "LabelHighlight"), new SolidColorBrush(Colors.Transparent)); style.Resources.Add(new ComponentResourceKey(typeof (XamDataGrid), "LabelBackground"), new SolidColorBrush(Colors.Transparent)); foreach (var source in attributes.Where(attribute => attribute.GroupBy).OrderBy(attribute => attribute.Order)) { var brush = new LinearGradientBrush() { Opacity = 0.5, StartPoint = new Point(0.5,0), EndPoint = new Point(0.5,1)}; brush.GradientStops.Add(new GradientStop(Colors.Snow, 0)); if (source.ColourBinding) { var stop = new GradientStop(source.ColourCodeFinish, 0.9); var binding = new Binding("ChildRecords[0].DataItem." + attributes.FirstOrDefault(attribute => attribute.ColourBound).PropertyName); BindingOperations.SetBinding(stop, GradientStop.ColorProperty, binding); brush.GradientStops.Add(stop); } else { brush.GradientStops.Add(new GradientStop(source.ColourCodeStart, 0.1)); brush.GradientStops.Add(new GradientStop(source.ColourCodeFinish, 0.9)); } e.FieldLayout.SortedFields.Add(new FieldSortDescription(source.PropertyName, ListSortDirection.Ascending, true)); brush.GradientStops.Add(new GradientStop(Colors.Snow, 1)); var trigger = new DataTrigger() {Value = source.PropertyName}; trigger.Binding = new Binding("GroupByField.Name") { BindsDirectlyToSource = true }; trigger.Setters.Add(new Setter(BackgroundProperty, brush)); style.Triggers.Add(trigger);
} XamDataGrid.Resources.Add("ColourKey", style); } var statbinding = new Binding() { Source = XamDataGrid.Resources["ColourKey"], BindsDirectlyToSource = true }; BindingOperations.SetBinding(XamDataGrid.FieldSettings, FieldSettings.GroupByRecordPresenterStyleProperty, statbinding);}