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

In 2010 Q3 RadGridView fails when using DeferRefresh

2 Answers 287 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.
Alex
Top achievements
Rank 1
Alex asked on 19 Nov 2010, 01:53 PM
Hello!
I have a PagedCollectionView in my view model and RadGridView in XAML with ItemsSource binded to PagedCollectionView.
When i try to call View.SortDescriptions.Clear() inside the scope of DeferRefresh()
RadGridView fails with InvalidOperationException:
Cannot change or check the contents or current position of the PagedCollectionView while Refresh is being deferred.

Here is my xaml:
<UserControl x:Class="RadGridViewTest.MainPage"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:local="clr-namespace:RadGridViewTest">
    <UserControl.Resources>
        <local:MainPageViewModel x:Key="viewModel" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" DataContext="{StaticResource viewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadGridView ItemsSource="{Binding View}" />
        <Button Grid.Row="1" Margin="5" Content="Clear sorting"
                Command="{Binding ClearSorting}" HorizontalAlignment="Center" />
    </Grid>
</UserControl>

and view model:
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
namespace RadGridViewTest
{
    public class MainPageViewModel
    {
        private readonly ObservableCollection<string> _innerCollection;
        public MainPageViewModel()
        {
            _innerCollection = new ObservableCollection<string> { "Taganrog", "Cherven Bryag" };
            View = new PagedCollectionView(_innerCollection);
            ClearSorting = new DelegateCommand(onExecuteClearSorting);
        }
        public ICommand ClearSorting { get; private set; }
        public PagedCollectionView View { get; private set; }
        private void onExecuteClearSorting()
        {
            using (View.DeferRefresh()) // Comment this line to avoid exception
            {
                try { View.SortDescriptions.Clear(); } // This is the problem!!!
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
        }
    }
    public class DelegateCommand : ICommand
    {
        private readonly Action _executeAction;
        public DelegateCommand(Action executeAction)
        {
            _executeAction = executeAction;
        }
        public bool CanExecute(object parameter) { return true; }
        public void Execute(object parameter) { _executeAction(); }
        public event EventHandler CanExecuteChanged;
    }
}

When i commented line with using (View.DeferRefresh()) no exception occured.
Standart DataGrid also works well with DeferRefresh.

2 Answers, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 19 Nov 2010, 05:13 PM
Hi Alex,

 Unfortunately there is little we can do about this error, as ICollectionView does not expose a flag, signalling if it's deferring a refresh. What you can do is use our QueryableCollectionView in your ViewModel and bind RadGridView to that.

Best wishes,
Yavor Georgiev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Alex
Top achievements
Rank 1
answered on 24 Nov 2010, 08:12 AM
Thanks. It works.
Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Alex
Top achievements
Rank 1
Share this question
or