After updating to q2 2011 sp1 we are having a problem (didn't happen before). I have included source below to illustrate the problem. It is very similar to one scenario in our app. If you hit the load button two times you get a crash upon clicking the second time with a null reference exception. This only happens if you hide the column with the aggregate before the load. If you comment out that line, it doesn't crash. In our scenario, the user may have hidden some of the columns, including some that have aggregates.
We've had to comment out all aggregate columns to get around this, which is not pleasing our clients. Any suggestion? Thanks.
We've had to comment out all aggregate columns to get around this, which is not pleasing our clients. Any suggestion? Thanks.
<
UserControl
x:Class
=
"TestGrid.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Button
Click
=
"Button_Click"
Content
=
"Load"
/>
<
telerik:RadGridView
x:Name
=
"grid"
Grid.Row
=
"1"
AutoGenerateColumns
=
"False"
ShowColumnFooters
=
"True"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Quantity}"
>
<
telerik:GridViewDataColumn.AggregateFunctions
>
<
telerik:SumFunction
Caption
=
"Total:"
/>
</
telerik:GridViewDataColumn.AggregateFunctions
>
</
telerik:GridViewDataColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
<
telerik:RadDataPager
x:Name
=
"pageCtrl"
Grid.Row
=
"2"
/>
</
Grid
>
</
UserControl
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
System.Collections.ObjectModel;
namespace
TestGrid
{
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
}
private
void
Button_Click(
object
sender, RoutedEventArgs e)
{
LoadData();
}
private
void
LoadData()
{
// comment out this line and you can click the button as many times as you'd like
// but with it uncommented you can only click it it once and it crashes on the second click
if
(grid.Columns[1].IsVisible) grid.Columns[1].IsVisible =
false
;
var widgets =
new
List<Widget>();
for
(
int
i = 0; i < 10; i++)
{
widgets.Add(
new
Widget() { Name =
string
.Format(
"Widget {0}"
, i), Quantity = 1 });
}
pageCtrl.Source = widgets;
grid.ItemsSource = pageCtrl.PagedSource;
}
}
public
class
Widget
{
public
string
Name {
get
;
set
; }
public
int
Quantity {
get
;
set
; }
}
}