This question is locked. New answers and comments are not allowed.
Hello, I'm having a problem on displaying my GridViewGroupRow. I have a RadGrid named RadtabDaily
and RadItems named Sunday - Friday respectively. Each tabitem has its own RadGrid, named: GridViewMonday, to GridViewSunday. My problem is that
the GridGroupFooter does not appear. this happens randomly. (the GridViewGroupRow appears in GridViewFriday, but
not in other Grids.
Attached here is my XAML code, C# code and Screenshot.
<telerik:RadTabItem Header="Saturday" Name="TabSaturday" Height="70"> <telerik:RadGridView AutoGenerateColumns="False" Margin="15,13,12,17" ShowGroupFooters="True" ItemsSource="{Binding Customers}" x:Name="GridViewSaturday" CanUserDeleteRows="{Binding IsChecked, Mode=TwoWay, ElementName=CanUserDeleteRowsCheckBox}" ShowColumnFooters="True" CanUserFreezeColumns="False" DataContext="{StaticResource MyViewModel}"> <telerik:RadGridView.GroupRowStyle> <Style TargetType="telerik:GridViewGroupRow"> <Setter Property="ShowHeaderAggregates" Value="False" /> </Style> </telerik:RadGridView.GroupRowStyle> <telerik:RadGridView.Columns> <telerik:GridViewColumn Header="Add"> <telerik:GridViewColumn.CellTemplate> <DataTemplate> <Button Content="Add" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadGridView}}, Path=DataContext}" Command="{Binding DeleteCrewCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewCell}}, Path=DataContext}" IsEnabled="True"> </Button> </DataTemplate> </telerik:GridViewColumn.CellTemplate> </telerik:GridViewColumn> <telerik:GridViewColumn Header="Delete"> <telerik:GridViewColumn.CellTemplate> <DataTemplate> <Button Content="Delete" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadGridView}}, Path=DataContext}" Command="{Binding DeleteCrewCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewCell}}, Path=DataContext}" IsEnabled="True"> </Button> </DataTemplate> </telerik:GridViewColumn.CellTemplate> </telerik:GridViewColumn> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Customer" Width="200"/> <telerik:GridViewComboBoxColumn Header="Project" DataMemberBinding="{Binding ProjectId}" SelectedValueMemberPath="ID" DisplayMemberPath="Name" ItemsSource="{Binding Projects, Source={StaticResource MyViewModel}}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Task}" Header="Task" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Duration}" Header="Duration"> <telerik:GridViewDataColumn.AggregateFunctions> <telerik:SumFunction Caption="Total: "/> </telerik:GridViewDataColumn.AggregateFunctions> </telerik:GridViewDataColumn> <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Description" Width="275"/> <!--<telerik:GridViewDataColumn DataMemberBinding="{Binding TotalPerCustomer}" Header="Total"> <telerik:GridViewDataColumn.AggregateFunctions> <telerik:SumFunction Caption="Grand Total: "/> </telerik:GridViewDataColumn.AggregateFunctions> </telerik:GridViewDataColumn>--> </telerik:RadGridView.Columns> </telerik:RadGridView> </telerik:RadTabItem>
V
CC# Code:
ColumnGroupDescriptor descriptor = new ColumnGroupDescriptor();
descriptor.Column = this.GridViewSaturday.Columns["Duration"];
descriptor.Column = this.GridViewSunday.Columns["Duration"];
descriptor.Column = this.GridViewMonday.Columns["Duration"];
descriptor.Column = this.GridViewTuesday.Columns["Duration"];
descriptor.Column = this.GridViewWednesday.Columns["Duration"];
descriptor.Column = this.GridViewThursday.Columns["Duration"];
descriptor.Column = this.GridViewFriday.Columns["Duration"];
this.GridViewSaturday.GroupDescriptors.Add(descriptor);
this.GridViewSunday.GroupDescriptors.Add(descriptor);
this.GridViewMonday.GroupDescriptors.Add(descriptor);
this.GridViewTuesday.GroupDescriptors.Add(descriptor);
this.GridViewWednesday.GroupDescriptors.Add(descriptor);
this.GridViewThursday.GroupDescriptors.Add(descriptor);
this.GridViewFriday.GroupDescriptors.Add(descriptor);
}
public class MyGroupFooterCellStyleSelector : StyleSelector
{
public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
{
GridViewGroupFooterCell cell = container as GridViewGroupFooterCell;
GridViewGroupFooterRow groupFooterRow = cell.ParentRow as GridViewGroupFooterRow;
GridViewGroupRow groupRow = groupFooterRow.ParentGroupRow;
QueryableCollectionViewGroup group = groupRow.DataContext as QueryableCollectionViewGroup;
if (group != null)
{
AggregateFunction f = cell.Column.AggregateFunctions.FirstOrDefault();
if (f != null)
{
AggregateResult result = group.AggregateResults[f.FunctionName];
Style style = new Style(typeof(GridViewGroupFooterCell));
if (result != null && result.Value.GetType() == typeof(double) && (double)result.Value > 10)
{
style.Setters.Add(new Setter(GridViewGroupFooterCell.BackgroundProperty, GetColorFromHexa("#7F2FB3FD")));
}
return style;
}
}
return new Style(typeof(GridViewGroupFooterCell));
}
public static SolidColorBrush GetColorFromHexa(string hexaColor)
{
return new SolidColorBrush(
Color.FromArgb(
Convert.ToByte(hexaColor.Substring(1, 2), 16),
Convert.ToByte(hexaColor.Substring(3, 2), 16),
Convert.ToByte(hexaColor.Substring(5, 2), 16),
Convert.ToByte(hexaColor.Substring(7, 2), 16)
)
);
}