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

Adding GroupDescriptorCollection causes NullReferenceException

4 Answers 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 26 Nov 2011, 08:07 PM
I am basically just trying to set the default group on a GridView but when I add the GroupDescriptorCollection the app throws a NullReferenceException. I am using a custom data object with defined properties and have also tried it with the DataGrid, same error both ways. How can I set the default grouping on a GridView?

Thanks!

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 28 Nov 2011, 07:28 AM
Hi,

 Have you checked "Grouping" category in our demos?

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jfkrueger
Top achievements
Rank 1
answered on 28 Nov 2011, 05:38 PM

Hello,

Thank you for the response. Yes, I have checked those demos which is where I got the code to do this in the first place (From the custom aggregates demo). Here is my grid...

<telerik:RadGridView x:Name="RadGridViewStopLossDetails" 
                            ItemsSource="{Binding StopLossDetailsGridData}"
                            AutoGenerateColumns="false" ShowGroupPanel="True" FontSize="9"
                            IsFilteringAllowed="False" ShowColumnFooters="True" ShowGroupFooters="True" 
                            Margin="5,10,0,0"
                            Grid.Column="0"
                            Grid.Row="1"
                            VerticalAlignment="Top" 
                            RowIndicatorVisibility="Collapsed"
                            AutoExpandGroups="True"
                        Height="Auto"
                        Width="Auto" HorizontalAlignment="Center">
  
    <telerik:RadGridView.Columns>
  
        <telerik:GridViewDataColumn IsReadOnly="True" Header="Date Requested" DataMemberBinding="{Binding DateRequested}" TextWrapping="wrap" IsVisible="True" UniqueName="DateRequested">
            <telerik:GridViewDataColumn.Footer>
                <TextBlock Text="Totals:" />
            </telerik:GridViewDataColumn.Footer>
        </telerik:GridViewDataColumn>
  
        <telerik:GridViewDataColumn IsReadOnly="True" Header="Amount Requested:" DataMemberBinding="{Binding AmountRequested}" TextWrapping="NoWrap" DataFormatString="c" >
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction SourceField="AmountRequested" ResultFormatString="{}{0:c}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
  
        <telerik:GridViewDataColumn IsReadOnly="True" Header="Date Reimbursed" DataMemberBinding="{Binding DateReimbursed}" TextWrapping="NoWrap" UniqueName="DateReimbursed" />
  
        <telerik:GridViewDataColumn IsReadOnly="True" Header="Amount Reimbursed" DataMemberBinding="{Binding AmountReimbursed}" TextWrapping="NoWrap" DataFormatString="c">
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction SourceField="AmountReimbursed" ResultFormatString="{}{0:c}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
  
        <telerik:GridViewDataColumn IsReadOnly="True" Header="% Reimbursed" DataMemberBinding="{Binding PercentReimbursed}" TextWrapping="NoWrap" DataFormatString="{}{0:0%}">
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction SourceField="PercentReimbursed" ResultFormatString="{}{0:0%}" />
            </telerik:GridViewDataColumn.AggregateFunctions>
        </telerik:GridViewDataColumn>
  
    </telerik:RadGridView.Columns>
                  
    <telerik:RadGridView.GroupDescriptors>
        <telerik:ColumnGroupDescriptor Column="{Binding Columns[\DateRequested\], ElementName=RadGridViewStopLossDetails}" SortDirection="Ascending" />
    </telerik:RadGridView.GroupDescriptors>
  
  
</telerik:RadGridView>
0
Yordanka
Telerik team
answered on 29 Nov 2011, 12:52 PM
Hi Jfkrueger,

I've tried to reproduce the problem using the xaml provided and it works fine on my end. You can find my test application attached. Can you give it a try and modify it in order to demonstrate the problem?

All the best,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Missing User
answered on 23 Dec 2011, 05:26 PM
Hi jfkrueger !

I don't know if you already solve your issue, i had this same problem once, I always get the NullReference error when the Grid Loads

The problem in my case are caused by a little mistake, the two columns that i'm using in the GroupDescriptor are binding to properties, but the Name of the properties in XAML are wrong. Because of that the Grid try to group the columns but it just can't because their are null, so theres nothing to group!

So, when i fix the Binding of the columns all works again perfectly.

I hope that help you.




Tags
GridView
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
Vlad
Telerik team
jfkrueger
Top achievements
Rank 1
Yordanka
Telerik team
Missing User
Share this question
or