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
MainWindow.xaml.cs
MainWindowViewModel.cs
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;
}
}
}