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

Question: How to set multiple group in radgridview??

1 Answer 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 23 Mar 2010, 03:01 PM
Hello,
I would like to know how to set 2 groups in a radgridview adding 3 sum functions in the second group.
I must admit I cannot do it....
Thanks a lot....

Nick

For better details what I try to do is in the following code

<telerik:RadGridView x:Name="radGridInvoiceDetails" ShowGroupPanel="False" AutoGenerateColumns="False" Height="245" Width="920" ItemsSource="{Binding}" HorizontalAlignment="Center" DataLoadMode="Asynchronous">  
    <telerik:RadGridView.Columns> 
        <telerik:GridViewDataColumn Header="ProductFamily" DataMemberBinding="{Binding ProductFamilyDescription}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" IsVisible="False"/>  
        <telerik:GridViewDataColumn Header="Prodotto"      DataMemberBinding="{Binding ProductDescription}"       IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" IsVisible="False"/>  
        <telerik:GridViewDataColumn Header="Numero"        DataMemberBinding="{Binding BillNumberString}"         IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="50" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Data"          DataMemberBinding="{Binding BillDate}"                 IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="50" DataFormatString="{}{0:dd/MM/yyyy}"/>  
        <telerik:GridViewDataColumn Header="Qta"           DataMemberBinding="{Binding ProductQuantity}"          IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="50" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Prz.Uni"       DataMemberBinding="{Binding ProductFee}"               IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="50" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Tot.Prod"      DataMemberBinding="{Binding ProductTotal}"             IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="75" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Scontato"      DataMemberBinding="{Binding ProductDiscountedTotal}"   IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="75" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Trasporto"     DataMemberBinding="{Binding TransportTotal}"           IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="75" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Scontato"      DataMemberBinding="{Binding TransportDiscountedTotal}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="75" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Sconto totale" DataMemberBinding="{Binding TotalDiscountAmount}"      IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="75" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Imponibile"    DataMemberBinding="{Binding TotalBill}"                IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="75" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="IVA"           DataMemberBinding="{Binding VATString}"                IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="50"                             TextAlignment="Right"/>  
        <telerik:GridViewDataColumn Header="Totale"        DataMemberBinding="{Binding TotalVAT}"                 IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="100" DataFormatString="{}{0:N2}" TextAlignment="Right"/>  
        <telerik:GridViewDataColumn x:Name="columnView" IsFilterable="False" IsSortable="False" Width="40" IsReadOnly="True">  
            <telerik:GridViewColumn.CellTemplate> 
                <DataTemplate> 
                    <telerik:RadButton x:Name="buttonView" Click="buttonView_Click" Background="White" BorderBrush="White" Loaded="buttonView_Loaded">  
                        <Image Height="20" Width="20" Source="/Raise.FarinaEzio.SIB.Client.Management.GUI.BusinessManagement.Controls;component/Images/Edit.png"/>  
                        <Button.ToolTip> 
                            <StackPanel Orientation="Horizontal">  
                                <Image Source="/Raise.FarinaEzio.SIB.Client.Management.GUI.BusinessManagement.Controls;component/Images/Edit.png"/>  
                                <Label Content="Visualizza la bolla"/>  
                            </StackPanel> 
                        </Button.ToolTip> 
                    </telerik:RadButton> 
                </DataTemplate> 
            </telerik:GridViewColumn.CellTemplate> 
        </telerik:GridViewDataColumn> 
    </telerik:RadGridView.Columns> 
    <!--<telerik:RadGridView.GroupDescriptors> 
        <telerik:GroupDescriptor Member="ProductFamilyDescription" SortDirection="Ascending"/>  
        <telerik:GroupDescriptor Member="ProductDescription" SortDirection="Ascending" /> 
    </telerik:RadGridView.GroupDescriptors>--> 
</telerik:RadGridView> 
 

in the radgridview of this XAML code I have to programmatically add two groups,the second of which must also make 3 sum funtions.
Following examples I have found in this site I have written this code

private void InitInvoiceDetails()  
{  
    try 
    {  
        radGridInvoiceDetails.SelectedItem = null;  
        radGridInvoiceDetails.ItemsSource = null;  
        radGridInvoiceDetails.GroupDescriptors.Clear();  
 
        if (CurrentMaster != null)  
        {  
            var collection = from d in dc.InvoiceDetails  
                             where d.IdInvoiceMaster == CurrentMaster.Id  
                             orderby d.IdProductType, d.ProductDescription, d.BillNumber  
                             select d;  
            radGridInvoiceDetails.ItemsSource = collection.ToList();  
        }  
 
        GroupDescriptor descriptor = new Telerik.Windows.Data.GroupDescriptor();  
        descriptor.Member = "ProductFamilyDescription";  
        descriptor.DisplayContent = "Famiglia";  
        descriptor.SortDirection = ListSortDirection.Ascending;  
        radGridInvoiceDetails.GroupDescriptors.Add(descriptor);  
 
        descriptor = new Telerik.Windows.Data.GroupDescriptor();  
        var sumFunction = new Telerik.Windows.Data.SumFunction();  
        sumFunction.ResultFormatString = "{0:N2}";  
        sumFunction.SourceField = "ProductQuantity";  
        sumFunction.Caption = "Totale Quantità";  
        descriptor.AggregateFunctions.Add(sumFunction);  
 
        sumFunction = new Telerik.Windows.Data.SumFunction();  
        sumFunction.ResultFormatString = "{0:N2}";  
        sumFunction.SourceField = "TotalBill";  
        sumFunction.Caption = "Totale Imponibile";  
        descriptor.AggregateFunctions.Add(sumFunction);  
 
        sumFunction = new Telerik.Windows.Data.SumFunction();  
        sumFunction.ResultFormatString = "{0:N2}";  
        sumFunction.SourceField = "TotalVAT";  
        sumFunction.Caption = "Totale Con IVA";  
        descriptor.AggregateFunctions.Add(sumFunction);  
 
        descriptor.Member = "ProductDescription";  
        descriptor.DisplayContent = "Prodotto";  
        descriptor.SortDirection = ListSortDirection.Ascending;  
        radGridInvoiceDetails.GroupDescriptors.Add(descriptor);  
    }  
    catch (Exception ex)  
    {  
        throw ex;  
    }  
}  
 

It happens that the first time I bind data in the radgrid view the groups are duplicated.
The first does not contains the sum values, the second yes.

The second time an exception is thrown.
System.ArgumentException was unhandled by user code  
  Message="The value \"[Group: Key=RCK 25.0 S3 F.FULLER NO; ItemCount=1; HasSubgroups=False; ParentGroup=null];\" is not of type \"Raise.FarinaEzio.SIB.Client.Management.DataContext.InvoiceDetail\" and cannot be used in this generic collection.\r\nParameter name: value" 
  Source="mscorlib" 
  ParamName="value" 
  StackTrace:  
       at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)  
       at System.Collections.Generic.List`1.VerifyValueType(Object value)  
       at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)  
       at Telerik.Windows.Data.QueryableCollectionView.PopulateInternalList(IQueryable view) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 482  
       at Telerik.Windows.Data.QueryableCollectionView.<>c__DisplayClassa.<CreateInternalList>b__6(Object s, DoWorkEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 458  
       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)  
       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)  
  InnerException:   
 

Hope this details help you to help me...

Bye

1 Answer, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 25 Mar 2010, 05:04 PM
Hi Nick,

In order to have the aggregate functions in both groups you have to add them to the both group descriptors.

Regarding the exception it seems like an issue with async data loading. Do you get the same exception if you set Synchronous DataLoadMode? Also it is a good practices when you add more than one group descriptor at a time to use DeferRefresh() method:
this.MyRadGridView.ItemsSource = ...
 
using(this.MyRadGridView.DeferRefresh())
{
  // Add descriptors here...
}

Hope this helps,
Stefan Dobrev
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
Nick
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Share this question
or