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

VirtualQueryableCollectionView weird behavior

4 Answers 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 21 Apr 2017, 08:08 AM

Dear Telerik,

I encountered pretty weird behavior  while using VirtualQueryableCollectionView+grid.

I have  a grid and a simple combobox for filtering. When I select a value in the combobox everything works as expected:

-- selected combobox value changed

-- handle property change event in the model

-- set collection total and reload required page

However if i click any cell I can see that virtual collection reloads ALL the pages. I attached a small repro u can play with.

Scenario 1: start the app - select a unit from the combobox - click any cell (e.g. top left cell) - check the output

Scenario 2: start the app - click the button - click any cell (e.g. top left cell) - check the output

-- 

Here is the xaml

 

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />

</Grid.RowDefinitions>

<telerik:RadButton Content="reload" HorizontalAlignment="Left" Margin="2" Command="{Binding ReloadCommand}" />

<telerik:RadComboBox  ItemsSource="{Binding Units}" HorizontalAlignment="Right" Margin="2"
EmptyText="select unit" SelectedItem="{Binding Unit, Mode=TwoWay}"/>

<telerik:RadGridView  AutoGenerateColumns="False" ShowGroupPanel="False" 
ItemsSource="{Binding Data}" Grid.Row="1" IsReadOnly="True"  >
<telerik:RadGridView.Columns>

<telerik:GridViewDataColumn DataMemberBinding="{Binding RowNo}" Header="row no" />

</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
</Window>

Here is the model

 

#region Usings
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Input;
using Telerik.Windows.Data;
#endregion

namespace WpfApplication1
{
public class Model
{
#region Class constants
private const int PAGE_SIZE = 100;
#endregion

#region Class members
private UnitType _unit;
protected VirtualQueryableCollectionView _data;
#endregion

#region Class properties
public IEnumerable<UnitType> Units
{
get
{
return Enum
.GetValues( typeof( UnitType ) )
.Cast<UnitType>()
.ToList();
}
}
public UnitType Unit 
{
get 
{
return _unit;
}
set 
{
_unit = value;

LoadHistory();
}
}
public VirtualQueryableCollectionView Data
{
get
{
return _data;
}
}
public CommandHandler ReloadCommand { get; set; }
#endregion

#region Class initialization
public Model() 
{
_data = new VirtualQueryableCollectionView()
{
LoadSize = 100
};

_data.ItemsLoading += ( o, ea ) => OnNeedDataPage( ea.StartIndex / _data.LoadSize );

ReloadCommand = new CommandHandler( x => LoadHistory(), true );
}
#endregion

#region Class event handlers
private void LoadHistory()
{
_data.ResetItems();
LoadHistory( 0 );
}
protected void OnNeedDataPage( int iPageIndex )
{

LoadHistory( iPageIndex );
}
private void LoadHistory( int iPageIndex )
{
var iTotalCount = 1000;
Debug.WriteLine( "load glass history page: " + iPageIndex );

if( iTotalCount != _data.VirtualItemCount )
{
_data.VirtualItemCount = iTotalCount;
}

int iStartIndex = iPageIndex * PAGE_SIZE;
var list = new List<TestData>();

for( int i = iPageIndex * PAGE_SIZE; i < iPageIndex * PAGE_SIZE + PAGE_SIZE; ++i )
{
list.Add( new TestData() { RowNo = i } );
}

_data.Load( iStartIndex, list );
}
#endregion

#region Class internal structs
public enum UnitType 
{
none,
a,
b
}
public class TestData
{
public int RowNo { get; set; }
}
#endregion
}

public class CommandHandler:ICommand
{
#region Class members
protected Action<object> _action;
protected bool _canExecute;
#endregion

#region Class events
public event EventHandler CanExecuteChanged;
public void FireCanExecuteChanged( bool b )
{
_canExecute = b;

if( null != CanExecuteChanged )
{
CanExecuteChanged( this, EventArgs.Empty );
}
}
#endregion

#region Class initialization
public CommandHandler( Action<object> action, bool canExecute )
{
_action = action;
_canExecute = canExecute;
}
#endregion

#region Class public methods
public bool CanExecute( object parameter )
{
return _canExecute;
}
public void Execute( object parameter )
{
_action( parameter );
}
#endregion
}
}

 

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 26 Apr 2017, 07:50 AM
Hi John,

Thanks for the code provided.

Its quite strange that the same code produces different behavior when triggered from RadComboBox selection and an ICommand. The only possible reason that I can think of is that in the case when all items are loaded, RadGridView is measured with infinity. Can you please verify the you are using the same view in both cases?

Regards,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
john
Top achievements
Rank 1
answered on 27 Apr 2017, 05:00 AM

As you can see from the xaml I provided i added three elements: grid + button + combo

That means i'm using the same container for both ICommand and combo event.

I repeat:

-- as soon as i select any values from the combo and click any cell in the grid virtual collection loads ALL the pages.If i select another value and click the cell nothing happens. Hence it happens only once.

-- if i start up the app click the button and click any cell - nothing weird happens. If after that without app restart i select anything from the combo and click any cell - boom

BTW: i reproduced  the same behavior with the native combobox :)

Please help.

 

 

 

 

 

 

 

0
Martin
Telerik team
answered on 01 May 2017, 02:00 PM
Hi John,

We are working with limited resources because of the national holidays in Bulgaria and will need some more time to look into the case. I will mark this ticket as requiring an additional answer and we will get back to you once we have more information on your scenario. Thank you for understanding.

Regards,
Martin Vatev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Stefan
Telerik team
answered on 02 May 2017, 01:58 PM
Hello John,

Thank you for your patience.

I performed various tests with the provided code and unfortunately, I am not able to replicate the behavior you are experiencing. Can you please check out the two videos that I prepared in the archive attached to my post? As you can see, the result in the output is the same when the data is loaded from the Command of the Button and the selection of the ComboBox. Can you please check this out? Am I missing anything?

Regards,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
john
Top achievements
Rank 1
Answers by
Stefan
Telerik team
john
Top achievements
Rank 1
Martin
Telerik team
Share this question
or