This is a migrated thread and some comments may be shown as answers.

Hide Group Header for Hidden Column

1 Answer 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 31 May 2011, 03:36 PM
Hi there,

I have a gridview with two columns - CAD Amount and USD Amount - that I hide/display based on a radiobutton choice.  In the grid, when a user groups by another column Employee, I display the sum of the CAD Amount and USD Amount in the group header.  Currently, both aggregate values are displayed even if only one of the CAD Amount or USD Amount columns is visible.   However, I would only like to display the sum for the column in the header if the column is visible.  Is this possible?

Here is the XAML code:
<telerik:RadGridView x:Name="CostDetailsGridView"
                                 Width="594"
                                 Height="370"
                                 IsReadOnly="True"
                                 AutoGenerateColumns="False"
                                 ShowColumnFooters="True"
                                 ShowGroupFooters="True">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding PostingDate}" DataFormatString="{}{0:d}" Header="Posting Date" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding AmountCAD}" Header="Amount (in CA$)" TextAlignment="Right" FooterTextAlignment="Right" DataFormatString="{}{0:c0}" IsGroupable="False">
                        <telerik:GridViewDataColumn.AggregateFunctions>
                            <telerik:SumFunction SourceField="AmountCAD" ResultFormatString="{}{0:c0}" />
                        </telerik:GridViewDataColumn.AggregateFunctions>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding AmountUSD}" Header="Amount (in US$)" TextAlignment="Right" FooterTextAlignment="Right" DataFormatString="{}{0:c0}" IsGroupable="False" IsVisible="False">
                        <telerik:GridViewDataColumn.AggregateFunctions>
                            <telerik:SumFunction SourceField="AmountUSD" ResultFormatString="{}{0:c0}" />
                        </telerik:GridViewDataColumn.AggregateFunctions>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Employee}" Header="Employee" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Department}" Header="Department" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Reimbursement}" Header="Reimbursement" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ExpenseType}" Header="Expense Type" />                    
                </telerik:RadGridView.Columns>
                <telerik:RadGridView.GroupDescriptors>
                    <telerik:GroupDescriptor Member="Employee" DisplayContent="Employee" SortDirection="Ascending"/>
                </telerik:RadGridView.GroupDescriptors>
            </telerik:RadGridView>


Thanks,
Amy

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 02 Jun 2011, 08:29 AM
Hi Amy,

If you want to not include some AggregateFunction in a GroupFooter, you will need to manually remove it from the collection of AggregateFunctions associated to the GroupDescriptor. You may do this in the DataLoaded event of the GridView only the first time when it is raised. Once the event is raised, you will need to unsubscribe from it.

In the DataLoaded event you find all the AggregateFunctions of the invisible columns. Then you remove them from the GroupDecriptor like this:

this.clubsGrid.DataLoaded += new EventHandler<EventArgs>(clubsGrid_DataLoaded);
void clubsGrid_DataLoaded(object sender, EventArgs e)
        {
            this.clubsGrid.DataLoaded -= new EventHandler<EventArgs>(clubsGrid_DataLoaded);
 
            var functionsToRemove = this.clubsGrid.Columns
                .OfType<GridViewDataColumn>()
                .Where(c => c.IsVisible == false)
                .SelectMany(c => c.AggregateFunctions);
 
            if (this.clubsGrid.GroupDescriptors.Count > 0)
            {
                foreach (var item in functionsToRemove)
                {
                    (this.clubsGrid.GroupDescriptors[0] as GroupDescriptor).AggregateFunctions.Remove(item);
                }
            }
        }

Once you change the column to be visible again, you have to add its AggregateFunctions to the GroupDescriptor.

Is this workaround appropriate for your project.

Greetings,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Amy
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or