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

Async data load not working after hotfix

2 Answers 226 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Bob asked on 28 Sep 2011, 09:35 PM
I am using a RadGridView where the ItemsSource is bound to a QueryableCollectionView that contains a RadObservableCollection of data.  The data is loaded asynchronously from a web service, so on return from the service, the collection is updated by calling Clear, then AddRange, and then Refresh is called on the QueryableCollectionView.

This was working great until we applied the hotfix from 9/27 which we needed to fix another issue in the rich text editor.  Once we applied the hotfix, the grid would not display any data in the rows, but would recognize the correct amount of data rows.  The grid also does not display any filter buttons in the headers, and there is no change to the header state when sort is applied.  I can see my data in the collection, but the grid won't display the cell contents.

This is also not working in the 9/20 build, but works fine in the 7/12 build and previous.

I cannot reproduce the problem by making synchronous calls to load data.  This only happens when the Refresh is applied after a callback.

Thanks for any help.

Edit:  Any columns where we override CreateCellElement are working.  GridViewDataColumn without the override is not working.

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 29 Sep 2011, 07:10 AM
Hello,

 Are you referring to DataLoadMode="Asynchronous"? Since you already load data asynchronously from a service you do not need this setting. 

All the best,
Vlad
the Telerik team

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

0
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 29 Sep 2011, 03:57 PM
Hi Vlad,

I was not referring to DataLoadMode, and we do have that set to synchronous.

We think the problem is that we are severing and restoring a binding to the GridView ItemsSource in our framework before the data actually returns from the async call.  By disrupting the binding, the GridView is somehow not able to load the data correctly.

Here is our framework method that creates the problem.  This method was designed to display an error area at the bottom of the main display.

void WorkspaceView_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
    lock (this)
    {
        if (!hasBeenLoaded)
        {
            // Create a new DockPanel root
            DockPanel NewRoot = new DockPanel();
            NewRoot.LastChildFill = true;
 
            // Create a grid with two rows:  page content and error control
            Grid grid = new Grid();
 
            // Content area takes up all the space minus the button and error control area
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
 
            // Second row for the button area will take up as much space as needed
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0, GridUnitType.Auto) });
 
            // Third row will contain the error control
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0, GridUnitType.Auto) });
            NewRoot.Children.Add(grid);
 
            // Query the existing content
            FrameworkElement existingContent = this.Content as FrameworkElement;
            this.Content = null;
 
            // Create a scrollview for the existing content
            ScrollViewer ContentScrollView = new ScrollViewer() { HorizontalScrollBarVisibility = ScrollBarVisibility.Auto, VerticalScrollBarVisibility = ScrollBarVisibility.Auto };
            ContentScrollView.Name = "MainViewScrollViewer";
            ContentScrollView.Content = existingContent;
 
            // Create the error control
            ErrorDisplayView errorDisplayCtrl = new ErrorDisplayView();
 
            // Setup binding of the BottomContent property to the Content property of ContentControl at bottom of the screen
            Binding binding = new Binding();
            binding.Source = BottomContent;
            BottomContentArea.SetBinding(ContentControl.ContentProperty, binding);
 
            // Set the placement of the controls in grid
            if (Utility.UIHelpers.IsInDesignMode())
            {
                // Do not add busy indicator in design mode. 
                // It causes issues in Expression Blend
                Grid.SetRow(ContentScrollView, 0);
                grid.Children.Add(ContentScrollView);
            }
            else
            {
                // Add the busy indicator in run mode
                busy.IsIndeterminate = true;
                busy.DisplayAfter = TimeSpan.FromSeconds(0);
 
                Binding busyBinding = new Binding("IsBusy");
                busyBinding.Source = DataContext;
                busyBinding.Mode = BindingMode.OneWay;
                busy.SetBinding(RadBusyIndicator.IsBusyProperty, busyBinding);
 
                busy.Content = ContentScrollView;
                Grid.SetRow(busy, 0);
                grid.Children.Add(busy);
 
                // Bind the bottom content enabled state to the busy flag
                Binding BottomContentBusyBinding = new Binding("IsNotBusy");
                BottomContentBusyBinding.Source = DataContext;
                BottomContentBusyBinding.Mode = BindingMode.OneWay;
                BottomContentArea.SetBinding(ContentControl.IsEnabledProperty, BottomContentBusyBinding);
            }
 
            // Set the row position for bottom content and error display
            Grid.SetRow(BottomContentArea, 1);
            Grid.SetRow(errorDisplayCtrl, 2);
 
            // Add the controls to the grid, existing content will fill the screen
            grid.Children.Add(BottomContentArea);
            grid.Children.Add(errorDisplayCtrl);
 
            this.Content = NewRoot;
 
            // Set flag to avoid repeating startup
            hasBeenLoaded = true;
 
            IViewModel vw = DataContext as IViewModel;
            if (vw != null)
                vw.OnStartup();
 
            // Raise workspace loaded event
            RaiseWorkSpaceLoadedEvent();
        }
    }
}

Notice in the code above that the Content is set to null, then restored later in the method to NewRoot.  This causes the controls on the existing view to have their binding values nulled, then restored.  After this happens, any updates to the data bound to ItemsSource seems to be corrupt.  Although this had always worked with previous releases of the RadGridView, the latest hotfix is now breaking.

We are going to look into a different way to create our error area, and not have the binding severed.  There should be no issues with your hotfix if we rework this code.

Thanks,
Bob
Tags
GridView
Asked by
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Vlad
Telerik team
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Share this question
or