Layout is corrupted after changing ItemsSource

3 posts, 0 answers
  1. Roman
    Roman avatar
    12 posts
    Member since:
    Oct 2011

    Posted 30 Nov 2011 Link to this post


    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"
                     ItemsSource="{Binding ResultsSource}"
                     SelectedItem="{Binding SelectedItem, Mode=TwoWay}"

    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())
      if (this.VirtualizingPanel != null)
      if ((this.ItemsScrollViewer != null) && !this.ShouldKeepScrollState)
        if (this.ItemsScrollViewer.VerticalOffset > 0.0)
      this.InternalColumns.RecreateColumnsBlockListForVirtualizedRows = true;
      this.InternalColumns.RecreateColumnsBlockListForNonVirtualizedRows = true;
      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 
    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. Vera
    Vera avatar
    265 posts

    Posted 02 Dec 2011 Link to this post

    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,
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. Roman
    Roman avatar
    12 posts
    Member since:
    Oct 2011

    Posted 07 Dec 2011 Link to this post

    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
Back to Top