This question is locked. New answers and comments are not allowed.
Hi,
I get an InvalidOperationException when I try to apply a filter descriptors to my RadGridView or RadTreeListView with Silverlight 4.
I have implemented the code from this link to save and load the filter in my database, and it work like a charm in a seperate page. My problem is when I try to apply that same code to the filter on my main grid. Here is an example of my code:
XAML:
The
Code-behind:
Where
I get the InvalidOperationException on the last line of my code-behind (
Any idea how to solve this?
Thanks,
Gen
I get an InvalidOperationException when I try to apply a filter descriptors to my RadGridView or RadTreeListView with Silverlight 4.
I have implemented the code from this link to save and load the filter in my database, and it work like a charm in a seperate page. My problem is when I try to apply that same code to the filter on my main grid. Here is an example of my code:
XAML:
<telerik:RadDataFilter Name="radDataFilter2" Margin="0" Height="1" Grid.Row="0"
Source="{Binding Path=PagedSource,
ElementName=radDataPager2}" Visibility="Collapsed"/>
<telerik:RadGridView x:Name="radGridView"
ItemsSource="{Binding Path=FilteredSource,
ElementName=radDataFilter2}"
SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}" Height="436"
RowDetailsVisibilityMode="Collapsed" AutoGenerateColumns="False"
HorizontalAlignment="Left" Grid.Row="0" Width="976"
RowStyle="{StaticResource
DraggedRowStyle}"
dragAndDrop:RadDragAndDropManager.AllowDrop="True"
>
...
</telerik:RadGridView>
<telerik:RadDataPager x:Name="radDataPager2"
PageSize="15"
Source="{Binding
Path=DataGrid}"
Grid.Row="1" Width="976"
DisplayMode="All"
AutoEllipsisMode="Both"
NumericButtonCount="10"
IsTotalItemCountFixed="True" />DataGrid is filled in the
ViewModel, then it fires a message that my code-behind listens to.myDataGrid = new ObservableCollection<Item>();
//Add items to the list
OnPropertyChanged("DataGrid");
Messenger.Default.Send(new NotificationMessage<string>(CurrentFilterString));
Code-behind:
Messenger.Default.Register<NotificationMessage<string>>(this, LoadCustomFilter);
...
private void LoadCustomFilter(NotificationMessage<string> msg)
{
var serializer
= new
DataContractSerializer(typeof(FilterSet), new List<Type> { typeof(Filter) });
var encoding
= new
UTF8Encoding();
var stream
= new
MemoryStream(encoding.GetBytes(msg.Content));
var fs
= (FilterSet)serializer.ReadObject(stream);
radDataFilter1.FilterDescriptors.Clear();
radDataFilter1.FilterDescriptors.LogicalOperator = fs.Operator;
radDataFilter1.FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters));
}
GetFilterDescriptorsFromFilters(fs.Filters)
gets a List<IFilter>
and returns an LIEnumerable<IFilterDescriptor>
and msg.Content
is a string of XML style.I get the InvalidOperationException on the last line of my code-behind (
radDataFilter1.FilterDescriptors.AddRange(GetFilterDescriptorsFromFilters(fs.Filters));),
saying the the collection has changed.Any idea how to solve this?
Thanks,
Gen