When I change the ItemsSource in the Xceed DataGridControl my vertical and horizontal scroll bars immediately get reset to the top/left.
Any ideas how to prevent that from happening?
When I change the ItemsSource in the Xceed DataGridControl my vertical and horizontal scroll bars immediately get reset to the top/left.
Any ideas how to prevent that from happening?
I finally fixed and figured out why my scrollbars jump to the top/left each time my DataGrid refreshes.
Turns out the XAML binded to the View instead of to an actual datasource (DataView), thus each refresh replaced the view and the datasource. As a result of binding to a DataView, my scrollbars no longer jump, and my grid now populates instantly as before it tool 1-2 seconds.
I included my code changes in case that helps others in the future.
Old code binds to view:
<xcdg:DataGridControl Name="FileGrid"
AutoCreateColumns="False"
SelectionMode="Extended"
ReadOnly="True"
ItemsSource="{Binding FileGridDataSource}"
ItemScrollingBehavior="Immediate"
NavigationBehavior="RowOnly">
</xcdg:DataGridControl>
public sealed class DataGridViewModel : ViewModelBase
{
public DataGridCollectionView FileGridDataSource
{
get
{
return _fileGridDataBoundSource;
}
set
{
_fileGridDataBoundSource = value;
NotifyPropertyChanged("FileGridDataSource");
}
}
}
New code binds to a DataView:
<Window.Resources>
<xcdg:DataGridCollectionViewSource x:Name="FileGridView"
x:Key="fileView"
Source="{Binding Path=GridData}"
AutoFilterMode="And"
AutoCreateItemProperties="True"
AutoCreateForeignKeyDescriptions="True"
DefaultCalculateDistinctValues="False"/>
</Window.Resources>
<Grid>
<xcdg:DataGridControl Name="FileGrid"
AutoCreateColumns="False"
SelectionMode="Extended"
ReadOnly="True"
ItemsSource="{Binding Source={StaticResource fileView}}"
ItemScrollingBehavior="Immediate"
NavigationBehavior="RowOnly">
</xcdg:DataGridControl>
</Grid>
public sealed class DataGridViewModel : ViewModelBase
{
private DataTable _dt = new DataTable("MyDataTable");
public DataView GridData
{
get
{
return _dt.DefaultView;
}
}
}