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

[Solved] unable to get row count on grouping.

1 Answer 142 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sandy pochiraju
Top achievements
Rank 1
sandy pochiraju asked on 07 Sep 2009, 11:46 PM
hello all,

i am trying to get count of number rows when user groups the grid by any column in the grid.

however, i donot have column names specified in the .xaml file as i do so programmatically by assigning dataset to grid.datasource.

this is what i have in .xaml to get row count when user groups by a column - "Bin".

however, i donot get the row count at all, not even just the countfuntion.caption.

please let me know where am i going wrong here.

thanks so much,
sandy

<

 

UserControl x:Class="Intel.Cqn.Luminis.Silverlight.Screens.WIPScreen"

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

xmlns:HeaderMenu="clr-namespace:Intel.Cqn.Luminis.Silverlight"

 

 

xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"

 

xmlns:Controls1="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"

 

xmlns:data="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"

 

 

 

>

 

 

 

<Grid>

 

<telerik:RadGridView

 

 

Name="WipGrid"

 

CanUserReorderColumns="True"

 

CanUserInsertRows="False"

 

HeaderMenu:GridViewHeaderMenu.IsEnabled="True"

 

MultipleSelect="True"

 

AutoGenerateColumns="False"

 

ScrollMode="Deferred"

 

 

IsReadOnly="True"

 

>

 

<telerik:RadGridView.GroupDescriptors>

 

<data:GroupDescriptor Member="Bin">

 

 

<data:GroupDescriptor.AggregateFunctions>

 

<data:CountFunction Caption="total"/>

 

 

</data:GroupDescriptor.AggregateFunctions>

 

</data:GroupDescriptor>

 

</telerik:RadGridView.GroupDescriptors>

 

<Controls1:RadContextMenu.ContextMenu>

 

<Controls1:RadContextMenu x:Name="gridContextMenu">

 

<StackPanel Orientation="Horizontal">

 

<TextBlock Text="Choose columns: "/>

 

<ComboBox Name="ColumnComboBox" Width="24" />

 

</StackPanel>

 

<Controls1:RadMenuItem Header="Save View" Click="WipGrid_SaveView"/>

 

<Controls1:RadMenuItem Header="Refresh Data" Click="Refresh_Click"/>

 

</Controls1:RadContextMenu>

 

</Controls1:RadContextMenu.ContextMenu>

 

</telerik:RadGridView>

 

</Grid>

</

 

UserControl>

 

 

 

 

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 08 Sep 2009, 10:36 AM
Hello sandy pochiraju,

If you do not know your columns beforehand, you should attach to the Grouping event of the grid and add the aggregate function of your choice. It is done like this:

<UserControl x:Class="TicketID_240853_CountFunction.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    <Grid> 
        <telerik:RadGridView Name="playersGrid"  
                             AutoGenerateColumns="False" 
                             ColumnsWidthMode="Auto" 
                             AutoExpandGroups="True"
        </telerik:RadGridView> 
    </Grid> 
</UserControl> 
 

using System.Windows.Controls; 
using System.Windows.Data; 
using Telerik.Windows.Controls; 
using Telerik.Windows.Controls.GridView.GridView; 
using Telerik.Windows.Data; 
 
namespace TicketID_240853_CountFunction 
    public partial class MainPage : UserControl 
    { 
        public MainPage() 
        { 
            this.InitializeComponent(); 
 
            this.playersGrid.Columns.Add(new GridViewDataColumn {DataMemberBinding = new Binding("Name")}); 
            this.playersGrid.Columns.Add(new GridViewDataColumn {DataMemberBinding = new Binding("Number")}); 
            this.playersGrid.Columns.Add(new GridViewDataColumn {DataMemberBinding = new Binding("Position")}); 
            this.playersGrid.Columns.Add(new GridViewDataColumn {DataMemberBinding = new Binding("Country")}); 
 
            this.playersGrid.Grouping += this.OnGrouping; 
 
            this.playersGrid.ItemsSource = Club.GetPlayers(); 
        } 
 
        private void OnGrouping(object sender, GridViewGroupingEventArgs e) 
        { 
            e.GroupDescriptor.AggregateFunctions.Add(new CountFunction {Caption = "Count: "}); 
        } 
    } 

I have prepared a small sample project and attached it. I hope it helps. Let me know if that is not what you are after.

Best wishes,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
sandy pochiraju
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or