RadGridView ArgumentException Source type must be an enumerable type

1 Answer 53 Views
GridView
Daniel
Top achievements
Rank 1
Iron
Daniel asked on 24 Jun 2024, 07:01 AM
1.148 / 5.000
With the RadGridView, the binding for ItemsSource works perfectly and the data is displayed correctly. However, if I want to create a FilterDescriptor when a text box changed in the code-behind, I get a System.ArgumentException with the message 'Source type must be an enumerable type.' when executing the Add statement in the code

rgv.FilterDescriptors.Clear();

rgv.FilterDescriptors.LogicalOperator = FilterCompositionLogicalOperator.Or;

var cfd = new FilterDescriptor("columnName", FilterOperator.Contains, filterTxtBx.Text);

rgv.FilterDescriptors.Add(cfd);

with the stack trace

   at Telerik.Windows.Data.Expressions.EnumerableFilterOperatorExpressionBuilder.GenerateContainsMethodCall(Expression source, Expression value, Boolean shouldNegate)
   at Telerik.Windows.Data.Expressions.EnumerableFilterOperatorExpressionBuilder.GenerateContains(Expression left, Expression right)
   at Telerik.Windows.Data.Expressions.FilterOperatorExpressionBuilderBase.CreateExpression(Expression left, Expression right)
   at Telerik.Windows.Data.Expressions.OperatorValueFilterDescriptorExpressionBuilderBase.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.OperatorValueFilterDescriptorExpressionBuilderBase.CreateBodyExpression()
   at Telerik.Windows.Data.FilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
   at Telerik.Windows.Data.FilterDescriptorBase.CreateFilterExpression(Expression instance)
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
   at Telerik.Windows.Data.Expressions.FilterExpressionBuilder.CreateFilterExpression()
   at Telerik.Windows.Data.QueryableExtensions.Where(IQueryable source, CompositeFilterDescriptorCollection filterDescriptors)
   at Telerik.Windows.Data.QueryableCollectionView.CreateView()
   at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
   at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
   at Telerik.Windows.Data.QueryableCollectionView.get_InternalCount()
   at Telerik.Windows.Data.QueryableCollectionView.get_IsEmpty()
   at Telerik.Windows.Data.DataItemCollection.get_IsEmpty()
   at Telerik.Windows.Controls.GridView.BaseItemsControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.DataControl.OnItemsCollectionChangedDispatch(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.Listener`2.ReceiveWeakEvent(Object sender, TArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
   at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
   at Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()
   at Telerik.Windows.Data.QueryableCollectionView.OnFilterDescriptorsChanged()
   at Telerik.Windows.Data.QueryableCollectionView.OnFilterDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
   at Telerik.Windows.Data.FilterDescriptorCollection.InsertItem(Int32 index, IFilterDescriptor item)
   at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Insert(Int32 index, Object value)
   at Telerik.Windows.Data.CollectionHelper.Insert(IList target, IEnumerable newItems, Int32 startingIndex, IEqualityComparer itemComparer)
   at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
   at Telerik.Windows.Data.FilterDescriptorCollection.InsertItem(Int32 index, IFilterDescriptor item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)

But why an enumerable type is suddenly needed here is a mystery to me. Because the ItemsSource is enumerable anyway and the designer-generated data set classes for the items are not. How, above all, does he come to the strange assumption that such a type is suddenly needed here when the display has been working correctly and without problems up until then?
Dimitar
Telerik team
commented on 24 Jun 2024, 09:54 AM

Hi Daniel, 

Such an exception can occur when there is no memeber with such name. Please make sure that your model has a public property with this exact name. 

I hope this helps. Should you have any other questions do not hesitate to ask.
Daniel
Top achievements
Rank 1
Iron
commented on 24 Jun 2024, 10:05 AM | edited

I load the data by binding of RadGridView.ItemsSource to a enumerable property in the view model/data context of the window. I also changed the properties Name and Header of the GridViewDataColumn in the RadGridView.Columns in XAML to the name of the property in the model data class of the items in the source. So what should still be done? In addition, the data is displayed correctly and the name has always been copied, thus ruling out a typo, but has also been manually checked again. The DataMemberBinding is then used with the same name as Path to refer to the data property of the item.
Dimitar
Telerik team
commented on 25 Jun 2024, 05:41 AM

Hi Daniel, 

Can you send me the project or create a small sample project that reproduces this? This will allow me to properly investigate and determine what is causing this. 

Thank you in advance for your patience and cooperation. I am looking forward to your reply.

Daniel
Top achievements
Rank 1
Iron
commented on 01 Jul 2024, 10:24 AM | edited

I've now taken a closer look at the columns. It seems that the FormatException with the message 'The input string is in the wrong format.' always occurs in numeric columns with a non-numeric string value for the filter operator Contains. However, if you use a string with only digits, you get an ArgumentException with the message 'Source type must be an enumerable type.'. If you try using a parsed value for the column with numeric values, the problem is not solved either, but you get a NotImplementedException with the message 'The method or operation is not implemented.'.
No error occurs for all three cases for string columns.
Dimitar
Telerik team
commented on 02 Jul 2024, 05:45 AM

Hi Daniel, 

It sounds to me that the columns have the wrong FilterMemberType. However, without the project, I can only guess what is causing this. If you cannot attach it here I would suggest creating a new ticket which is a private thread and attach it there. Would that be possible for you? 

Regards,

Dimitar

 

1 Answer, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
Iron
answered on 02 Jul 2024, 10:22 AM
Now we have found the problem. It was the wrong column type for the 'Contains' operator. We thought that because of WPF and the usual conversion without any further steps, we could use numeric columns with the 'Contains' operator. But that is exactly not the case. 'Contains' only works with strings.
Tags
GridView
Asked by
Daniel
Top achievements
Rank 1
Iron
Answers by
Daniel
Top achievements
Rank 1
Iron
Share this question
or