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

Code Filter only works if grid has been filtered through interface first

4 Answers 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jennifer
Top achievements
Rank 1
Jennifer asked on 30 Apr 2012, 02:13 PM
Hi,

I have an odd problem. I have a class that has several levels -- sections, then a dummy level, so that products can be a radgrid under the sections panel bar, and then products by location. I am trying to add the ability to condense the view so that users can choose to see all available items, or just those they have selected. My Telerik Controls are version 2012.1.326.1050, so I am using the IColumnFilterDescription formulation and trying to follow your documentation for this version of the controls. The odd thing is that, if I filter first using the interface the button works fine--and there are six separate grids, one for each section, and the button works to condense and expand all of them as long as I have applied or applied and removed one filter (on any column) in one grid. I'm guessing that somthing is not initialized, and I am getting a null exception in silverlight when I step through it, but nothing that I check seems to be null-- the column is there, the columndescriptor is there, it fails on ResumeNotifications, but again it works fine after one grid is filtered in the interface first.

 

private void BtnDisplay_Click(object sender, RoutedEventArgs e)
{
    _templateVM.blnViewCondensed = !_templateVM.blnViewCondensed;
    foreach (RadGridView tGrid in this.SectionGrid.PanelSections.ChildrenOfType<RadGridView>())
    {
        if (tGrid.DataContext is clsDummyLevel)
        {
            if (_templateVM.blnViewCondensed == true)
            {
 
                IColumnFilterDescriptor columnDescriptor = tGrid.Columns["Quantity"].ColumnFilterDescriptor;
                columnDescriptor.SuspendNotifications();
                columnDescriptor.FieldFilter.Clear();
                columnDescriptor.FieldFilter.Filter1.Operator = FilterOperator.IsGreaterThan;
                columnDescriptor.FieldFilter.Filter1.Value = 0;
                columnDescriptor.ResumeNotifications();
 
            }
            else
            {
                tGrid.Columns["Quantity"].ClearFilters();
            }
        }
    }
 
    //this.SectionGrid.PanelSections.UpdateLayout();
    if (_templateVM.blnViewCondensed == true)
    {
        BtnDisplay.Content = "Expand View";
    }
    else
    {
        BtnDisplay.Content = "Condense View";
    }
 
}

 

 



The program relies on a web service, so it would be hard to send you the whole project, but I am hoping that you will have some insight into what could be happening and what I need to do to get this to work. I did try putting a filter (that would not trigger any filtering) into the xaml for the grid using filter descriptors, but that caused an error as well.



Thank you,

Jennifer

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 30 Apr 2012, 02:28 PM
Hello,

That sounds really weird.

I have attached a dummy sample project with dummy data. Can you please try to modify it so it does throw the exception. Hopefully, if we can debug the exception we will understand what is going on.

Here are some other "shooting-in-the-dark" suggestions:

1. Try using RadGridView.FilterDescriptors.SuspendNotifications and RadGridView.FilterDescriptors.ResumeNotifications instead of the columnDescriptor.Suspend/Resume. 

2. Even better: Try not using the Suspend/Resume at all. Simply change the columnDescriptor.FieldFilter.Filter1.Value to the value that you want -- this will immediately change the filter. You don't have to Clear it before that either. Something like this:

IColumnFilterDescriptor columnDescriptor = tGrid.Columns["Quantity"].ColumnFilterDescriptor;
                columnDescriptor.FieldFilter.Filter1.Operator = FilterOperator.IsGreaterThan;
                columnDescriptor.FieldFilter.Filter1.Value = 0;


Or at least provide us with some kind of a stack trace so we can see where the exception is thrown.

We are looking forward to hearing from you.

All the best,
Ross
the Telerik team

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

0
Jennifer
Top achievements
Rank 1
answered on 30 Apr 2012, 03:34 PM
Hi, Ross,

I appreciate your help, but neither suggestion worked. I'm including the stack trace below. I was able to filter on a different column (IsSelected) using a boolean filter. My quantity column is calculated from the list of child products and is readonly, so I am guessing it has something to do with that, but I don't understand why it would work after the interface filter was triggered even in an unrelated grid and a different column.

If you have any thoughts after looking at the stack trace, I'd be happy to test them. Otherwise, I will go with using the other column--it's not exactly the same thing, but it is close enough.

Thank you for your help,

Jennifer

" at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.Windows.Data.Debugging.BindingBreakPoint.BreakOnSharedType(Type emittedType, BindingDebugState debugState, Int32 bindingNumber, Int32 line, Int32 column, Action callback)\r\n at System.Windows.Data.Binding.EnsureBreakPoint(BindingDebugState debugState, Action callback, Boolean canDelay)\r\n at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)\r\n at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)\r\n at S

ystem.Windows.DataContextChangedEventHandler.Invoke(Object sender, DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.O

nAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataCon

textChangedEventArgs e)\r\n at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)\r\n at System.Windows.FrameworkElement.OnPropertyChanged(DependencyProperty dp)\r\n at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)\r\n at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)\r\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)\r\n at System.Windows.FrameworkElement.set_DataContext(Object value)\r\n at Telerik.Windows.Controls.GridView.DataCellsPresenter.OnItemChanged(Object oldItem, Object newItem)\r\n at Telerik.Windows.Controls.GridView.DataCellsPresenter.set_Item(Object value)\r\n at Telerik.Windows.Controls.GridView.GridViewRowItem.OnItemChanged(Object oldItem, Object

newItem)\r\n at Telerik.Windows.Controls.GridView.GridViewRow.OnItemChanged(Object oldItem, Object newItem)\r\n at Telerik.Windows.Controls.RadRowItem.OnItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)\r\n at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)\r\n at System.Windows.DependencyObject.ClearValueInternal(DependencyProperty dp)\r\n at System.Windows.DependencyObject.ClearValue(DependencyProperty dp)\r\n at Telerik.Windows.Controls.GridView.GridViewRowItem.ClearRow(GridViewDataControl owningDataGrid)\r\n at Telerik.Windows.Controls.GridView.GridViewRow.ClearRow(GridViewDataControl owning

DataGrid)\r\n at Telerik.Windows.Controls.GridView.GridViewDataControl.ClearContainerForItemOverride(DependencyObject element, Object item)\r\n at Telerik.Windows.Controls.GridView.BaseItemsControl.Telerik.Windows.Controls.GridView.IGeneratorHost.ClearContainerForItem(DependencyObject container, Object item)\r\n at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.UnlinkContainerFromItem(DependencyObject container, Object item, Boolean isRecycled)\r\n at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.UnlinkContainerFromItem(DependencyObject container, Object item)\r\n at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.RecycleRealizedContainer(DependencyObject container, Object item)\r\n at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.RecycleAllRealizedContainersInBlock(RealizedItemBlock rib)\r\n at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.RecycleAllRealizedContainers()\r\n at Telerik.Windows.Controls.G

ridView.GridViewItemContainerGenerator.ReInitializeContainers()\r\n at Telerik.Windows.Controls.GridView.GridViewDataControl.ReuseContainersOnReset()\r\n at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsChanged(NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Controls.GridView.BaseItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)\r\n at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.Listener`2.ReceiveWeakEvent(Object sender, TArgs args)\r\n at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)\r\n at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(No

tifyCollectionChangedEventArgs args)\r\n at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()\r\n at Telerik.Windows.Data.QueryableCollectionView.RefreshInternal()\r\n at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()\r\n at Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()\r\n at Telerik.Windows.Data.QueryableCollectionView.OnFilterDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)\r\n at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\r\n at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at System.Collections.ObjectModel.ObservableCollection`1.InsertI

tem(Int32 index, T item)\r\n at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)\r\n at Telerik.Windows.Data.FilterDescriptorCollection.InsertItem(Int32 index, IFilterDescriptor item)\r\n at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)\r\n at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Insert(Int32 index, Object value)\r\n at Telerik.Windows.Data.CollectionHelper.Insert(IList target, IEnumerable newItems, Int32 startingIndex, IEqualityComparer itemComparer)\r\n at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)\r\n at Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)\r\n at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)\r\n at Sys

tem.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\r\n at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)\r\n at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)\r\n at Telerik.Windows.Data.FilterDescriptorCollection.InsertItem(Int32 index, IFilterDescriptor item)\r\n at System.Collections.ObjectModel.Collection`1.Add(T item)\r\n at Telerik.Windows.Controls.GridViewColumn.OnColumnFilterDescriptorPropertyChanged(Object sender, PropertyChangedEventArgs e)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(PropertyCha

ngedEventArgs args)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(String propertyName)\r\n at Telerik.Windows.Controls.GridView.ColumnFilterDescriptor.OnCompositeFilterPropertyChanged(Object sender, PropertyChangedEventArgs e)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(PropertyChangedEventArgs args)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(String propertyName)\r\n at Telerik.Windows.Data.CompositeFilterDescriptor.OnFilterDescriptorsItemChanged(Object sender, ItemChangedEventArgs`1 e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.RaiseGenericItemChanged(ItemChangedEventArgs`1 e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.OnItemChanged(ItemChangedEventArgs`1 e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.OnItemPropertyChanged(Object sender, PropertyChangedEventArgs e)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(PropertyChangedEventArgs args)\r\n at Telerik.Windows.Data.DescriptorBase.OnProper

tyChanged(String propertyName)\r\n at Telerik.Windows.Controls.GridView.FieldFilterDescriptor.OnCompositeFilterPropertyChanged(Object sender, PropertyChangedEventArgs e)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(PropertyChangedEventArgs args)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(String propertyName)\r\n at Telerik.Windows.Data.CompositeFilterDescriptor.OnFilterDescriptorsItemChanged(Object sender, ItemChangedEventArgs`1 e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.RaiseGenericItemChanged(ItemChangedEventArgs`1 e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.OnItemChanged(ItemChangedEventArgs`1 e)\r\n at Telerik.Windows.Data.ObservableItemCollection`1.OnItemPropertyChanged(Object sender, PropertyChangedEventArgs e)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(PropertyChangedEventArgs args)\r\n at Telerik.Windows.Data.DescriptorBase.OnPropertyChanged(String propertyName)\r\n at Telerik.Windows.Data.OperatorValue

FilterDescriptorBase.OnValuePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)\r\n at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)\r\n at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)\r\n at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)\r\n at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)\r\n at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)\r\n at Telerik.Windows.Data.OperatorValueFilterDescriptorBase.set_Value(Object value)\r\n at TSD_QuoteGenV2.MainPage.BtnDisplay_Click(Object sender, RoutedEventArgs e)"


0
Rossen Hristov
Telerik team
answered on 01 May 2012, 08:52 AM
Hello,

From the stack trace I can conclude that the actual filtering is not the real cause of the problem. Filtering happens successfully (since it is a data operation), but then when the grid has to re-create its view and update its visual children (i.e. GridViewRows) the problems begin. It has something to do with the amount of rows in the grid and vertical row virtualization, but it can be anything. The problem is definitely in the GridViewItemContainerGenerator.RecycleAllRealizedContainers() stuff and can be triggered by anything. 

You have found one of the ways to cause this by filtering, but this might happen every time when the view is re-created, i.e. sorting and grouping as well.

The bad thing is that I have been trying to reproduce this exception so I can debug it, but it does not want to happen on my end no matter what I try. So am kind of lost right now.

Kind regards,
Ross
the Telerik team

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

0
Jennifer
Top achievements
Rank 1
answered on 01 May 2012, 02:52 PM
Hi, Ross,

Thanks for taking a look at it. I'm sure that I have some less than ideal code in there. I'm guessing it has to do with the fact that my "IsSelected" can be updated by changing the quantities at the lower level (and the default quantites can be calculated in code if the IsSelected is checked, or removed if it is unchecked) and this is my first time I've used INotify with anything but simple get/set.  The odd thing is that it works great after that first interface filter, but nothing I do in terms of opening the child grids or doing some data updates first has the same effect. I'm okay with my workaround. When I get some time, I'll see if I can get a similar error with your sample project by summing something editable in the child grid to display in the higher level grid.

Thanks again for your help.

Jennifer

Tags
GridView
Asked by
Jennifer
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Jennifer
Top achievements
Rank 1
Share this question
or