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

RadGridView - AlternationCount - Refresh issue

2 Answers 261 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jean
Top achievements
Rank 1
Jean asked on 18 Oct 2011, 04:37 PM
Hi,

I have a very annoying issue. I bind the radgridview to a list of 100 items. I scroll down the list until item100. I rebind the gridview to a list of 3 items. The problem is the following: if AlternationCount is set to a value > 0, the list is not refreshed and the items in the list are not visible, until I force a refresh by maximizing the window that hosts the gridview. The scrollbar position is not reset to 0.

I attach an example of how to reproduce this problem using the latest stable version (.NET 3.5)

Steps:
1. run the app
2. scroll the grid to bottom
3. click on "Test" button
4. the grid is rebinded. The 3 items should be visible. If AlternationCount = 2 we have an issue. If you remove AlternationCount the items are visible.

MainWindow.xaml

<Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button Content="Test" Click="Button_Click" />
        <telerik:RadGridView Margin="0,10,0,0" Grid.Row="1" ItemsSource="{Binding Items}" AutoGenerateColumns="False" AlternationCount="2" AlternateRowBackground="#E6E3E3">
            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn Width="80" Header="ID">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ID}" VerticalAlignment="Center" HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewColumn Width="80" Header="Data">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>

MainWindow.xaml.cs
public partial class MainWindow : Window
   {
       public MainWindow()
       {
           InitializeComponent();
       }
 
       private void Button_Click(object sender, RoutedEventArgs e)
       {
           ((MainWindowViewModel)DataContext).Test2();
       }
 
       private void Window_Loaded(object sender, RoutedEventArgs e)
       {
           DataContext = new MainWindowViewModel();
           ((MainWindowViewModel)DataContext).Test1();
       }
   }


MainWindowViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
 
namespace GridViewBug
{
    public class Stuff
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
 
    public class MainWindowViewModel : INotifyPropertyChanged
    {
        private PropertyChangedEventHandler _propertyChangedEvent;
        public event PropertyChangedEventHandler PropertyChanged
        {
            add
            {
                _propertyChangedEvent += value;
            }
            remove
            {
                _propertyChangedEvent -= value;
            }
        }
 
        protected virtual void NotifyPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = _propertyChangedEvent;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
 
        private List<Stuff> _items;
        public List<Stuff> Items
        {
            get { return _items; }
            set
            {
                _items = value;
                NotifyPropertyChanged("Items");
            }
        }
 
        public void Test1()
        {
            Items = new List<Stuff>();
            for (int i = 0; i < 100; i++)
            {
                Items.Add(new Stuff() { Name = "item" + i.ToString(), ID = i });
            }
        }
 
        public void Test2()
        {
            var items = new List<Stuff>();
            items.Add(new Stuff() { Name = "item1", ID = 1 });
            items.Add(new Stuff() { Name = "item2", ID = 2 });
            items.Add(new Stuff() { Name = "item3", ID = 3 });
 
            Items = items;
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Yordanka
Telerik team
answered on 20 Oct 2011, 01:43 PM
Hi Jean,

The problem is resolved in the latest internal build - version 2011.2.1017. I've made a project based on the provided code snippets and attached it for a reference.
 
Kind regards,
Yordanka
the Telerik team

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

0
Jean
Top achievements
Rank 1
answered on 21 Oct 2011, 10:09 AM
Nice. It works fine now. Can I use this internal build in production as it's a very important issue for us.
Tags
GridView
Asked by
Jean
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Jean
Top achievements
Rank 1
Share this question
or