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

RadGridView Filter Error (Null values)

7 Answers 903 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MARCELO
Top achievements
Rank 1
MARCELO asked on 31 Oct 2019, 07:44 PM

I have a exception when i try to filter the null value for the column, when having Null descriptor and other values as well.  The binding is a dynamic object, i am setting the column type as expected.

I am using the version 2019.2.618.45 of telerik dll

Argument types do not match
   at System.Linq.Expressions.Expression.Constant(Object value, Type type)
   at Telerik.Windows.Data.Expressions.OperatorValueFilterDescriptorExpressionBuilderBase.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   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.DataItemCollection.get_Count()
   at Telerik.Windows.Controls.DataControl.ItemCoerce(DependencyObject d, Object baseValue)
   at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Telerik.Windows.Controls.DataControl.Telerik.Windows.Data.Selection.ISelectorInternal.set_SelectedItem(Object value)
   at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicSelectedItem()
   at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicPropertiesAndCleanUp()
   at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndAllowedSelection(ItemSelectionChange selectionChange)
   at Telerik.Windows.Controls.GridView.Selection.CompositeSelectionHandler.PerformRowSelection(Object dataItem, SelectionModificationOptions modificationOptions)
   at Telerik.Windows.Controls.GridView.Selection.CellAndRowSelectionDispatcher.HandleSelectionForCellInput(GridViewCell cell, SelectionModificationOptions allowedModifications)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.HandleMouseDownSelection(GridViewCell cell, Boolean allowDrag, Point mousePosition)
   at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

 

7 Answers, 1 is accepted

Sort by
0
MARCELO
Top achievements
Rank 1
answered on 01 Nov 2019, 05:25 PM
Hi, i forgot to mention that i have the SDK Samples and using the Visual Studio 2019(Framework 4.5.2). I tried the sample "Binding to DynamicObject" and i get the same error(exception), i made my dynamic class based on this sample.
0
Dilyan Traykov
Telerik team
answered on 04 Nov 2019, 10:44 AM

Hello Marcelo,

Thank you for the provided stack trace and image.

I tried to replicate the issue in the "Binding to DynamicObject" demo from our SDK Samples Browser, however, filtering the null values seems to work as expected at my end.

I'm attaching the modified example to my reply for your reference. Could you please have a look and let me know what modifications I can make to reproduce the exception?

Thank you in advance for your cooperation on the matter. I will be awaiting your reply.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
MARCELO
Top achievements
Rank 1
answered on 04 Nov 2019, 01:33 PM
Hello Dilyan, in another post i saw that to work with dynamic objects and grid view features ( filtering, grouping and sorting), it must set the column type in order to the grid view know how to work with the binding provided. With that in mind i modified your sample with this code:
<telerik:RadGridView ItemsSource="{Binding Data}" Margin="5" AutoGenerateColumns="False" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" Header="Id" DataType="{x:Type sys:Int32}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" DataType="{x:Type sys:String}" />
            </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

and set one of the values of `ID` column to `null`

var nullItem = new MyDataRow();
nullItem["ID"] = null;
nullItem["Name"] = null;
items.Add(nullItem);

Finally i run the project, filter by the `null` value the column `ID`(like the image that i attach), will not filter the column and when i close the filter window and click in any row the program will crash showing the exception "Argument types do not match".

0
MARCELO
Top achievements
Rank 1
answered on 04 Nov 2019, 01:42 PM
Hello Dilyan, i noticed that when i do not set the column `DataType` works as intended. It should been this way or should work in both ways ?
0
Dilyan Traykov
Telerik team
answered on 04 Nov 2019, 04:54 PM

Hello Marcelo,

Thank you for the clarification and provided snippets and image.

The reason for this exception is that the default Int32 type is not nullable. To avoid the exception, you can specify the DataType as suggested here.

<telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" Header="Id" DataType="{x:Type sys:Nullable`1[System.Int32]}" />
Please give this a try and let me know if it works for you.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
MARCELO
Top achievements
Rank 1
answered on 04 Nov 2019, 07:24 PM

Hello Dilyan,

Thank you for the response. How do i set the `DataType` Nullable int in code behind ?

0
Dilyan Traykov
Telerik team
answered on 05 Nov 2019, 09:15 AM

Hello Marcelo,

Here's how you can set the nullable DataType in code-behind:

(this.GridView.Columns["ID"] as GridViewDataColumn).DataType = typeof(int?);
Do let me know if this works for you.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
MARCELO
Top achievements
Rank 1
Answers by
MARCELO
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or