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

Layout is corrupted after changing ItemsSource

2 Answers 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roman
Top achievements
Rank 1
Roman asked on 30 Nov 2011, 11:01 AM
Hi,

I have the following situation:
  • columns are created in code. There are 20 columns.
  • ItemsSource is ICollectionView
  • grid has grouping by one column

<telerik:RadGridView x:Name="SearchResults"
                 ShowGroupPanel="True" IsReadOnly="True"
                 AutoGenerateColumns="False"
                 CanUserFreezeColumns="False"
                 RowIndicatorVisibility="Collapsed"
                 FrozenColumnCount="1"
                 ItemsSource="{Binding ResultsSource}"
                 SelectionMode="Single"
                 SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                 Grid.Row="1"
                 RowDetailsVisibilityMode="VisibleWhenSelected"
                 AutoExpandGroups="True"
                 EnableColumnVirtualization="True"
                 EnableFloatingButtons="True"
                 EnableRowVirtualization="True"
                 EnableActionButton="True">
</telerik:RadGridView:GridView>

When i change ItemsSource the layout become corrupted: 
  • the count of visible columns becomes 12, but the real number is 20
(i checked Columns property).
  • the group descriptor disappears 

What i found out is in OnItemsSourceChanged in GridViewDataControl
 there is if statement:


if (this.ControlLoaded || (this.ParentOfType<UIElement>() == null))
{
  if (!this.CommitEdit())
  {
    this.CancelEdit();
  }
  if (this.VirtualizingPanel != null)
  {
    this.VirtualizingPanel.ClearBringIntoViewContainer();
  }
  if ((this.ItemsScrollViewer != null) && !this.ShouldKeepScrollState)
  {
    this.ItemsScrollViewer.ScrollToTop();
    if (this.ItemsScrollViewer.VerticalOffset > 0.0)
    {
      base.UpdateLayout();
    }
    this.ItemsScrollViewer.InvalidateScrollInfo();
  }
  base.ItemContainerGenerator.Refresh();
  this.InvalidateInternalParts(true);
  base.InvalidateMeasure();
  base.InvalidateArrange();
  this._rowTrackingRoot.Clear();
  this.InternalColumns.RecreateColumnsBlockListForVirtualizedRows = true;
  this.InternalColumns.RecreateColumnsBlockListForNonVirtualizedRows = true;
  this.InternalColumns.InvalidateColumnWidthsCalculation();
  this.Bind(newValue);
}
else
{
  this.shouldBind = true;
  this.NewDataSource = newValue;
}

The problem occurs in Bind method. When in debug i skip Bind and move cursor
to else statement the grid 
displayed correctly:

this.shouldBind = true;
this.NewDataSource = newValue;

This situation could be prevented if i scroll through all columns to the end.
In this case all displayed 
correctly.
Also this behavior fixed when i add grouping by dragging column to group panel.

I hope you will help me to overcome this problem.

Best regards,
Roman Denysenko

2 Answers, 1 is accepted

Sort by
0
Vera
Telerik team
answered on 02 Dec 2011, 01:05 PM
Hello Roman,

Unfortunately, I was not able to reproduce the reported issues. I have prepared a sample project based on your requirements. May I ask you to take a look at it and to let me know in case I am missing something? Are you able to get the described behavior on it?

I am looking forward to hearing from you.

All the best,
Vera
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Roman
Top achievements
Rank 1
answered on 07 Dec 2011, 06:50 PM
Hello Vera,

The issue was detected. I set ItemsSource two times. And first time the ItemsSource is not exactly the same type as it was. When ItemsSource was setted the CollectionView was setted also. When CollectionView setting then old and new collections are checked if they are comparable. 
if they are comparable then GroupDescriptors and SortDescriptors are copied. If they not comparable collections of group descriptors and sort descriptors cleared.

Thank you, for help!

Best regards,
Roman Denysenko
Tags
GridView
Asked by
Roman
Top achievements
Rank 1
Answers by
Vera
Telerik team
Roman
Top achievements
Rank 1
Share this question
or