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

ArgumentException, binding to base type collection to GridView's ItemsSource

2 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lukasz
Top achievements
Rank 1
Iron
Lukasz asked on 01 Apr 2021, 09:07 AM
public class BaseType
{
      public int Id { get; set; }
}
  
public class ChildType1 : BaseType
{
      public string Name1 { get; set; }
}
  
public class ChildType2 : BaseType
{
      public string Name2 { get; set; }
}
  
// View model
  
public class WindowViewModel : ViewModelBase
{
     public ObservableCollection<BaseType> Items { get; }
}

I have a problem with binding to ItemSource from ViewModel with ObservableCollection. It's a generic collection of base type e.g. BaseType. Moreover I have a few child classes inherited from BaseType. They contain loads of additional properties of simple types such like double, int, string. For each child type I have another DataTemplate with different column definitions. When I'm opening the window, System.ArgumentException is throwing from Telerik with message "Property with name XXX cannot be fround on type BaseType". Due to this problem, GridView's performance is unacceptable (in release mode either).

How to solve that problem?
Thanks for help!

2 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 05 Apr 2021, 09:21 AM

Hello Lukasz,

Thank you for the shared code snippets. 

The described behavior is the expected one as the RadGridView is aware of the BaseType class, since this is the type of the Items collection populating its ItemsSource. Note, that the exception will only be thrown, if the exceptions are enabled in Visual Studio and will not prevent the normal execution of the application. 

If you are populating the ItemsSource of the RadGridView with only one type of object at a time (for example ChildType2), you can set the ItemType of the Items collection to it:

 this.gridView.Items.ItemType = typeof(ChildType2);

On a side note, you can also take a look at the following article: Tips and Tricks, which provides some suggestion for improving the RadGridView performance. 

I hope you find this information helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Lukasz
Top achievements
Rank 1
Iron
answered on 07 Apr 2021, 10:07 AM

Thank you for your quick response!

Tags
GridView
Asked by
Lukasz
Top achievements
Rank 1
Iron
Answers by
Vladimir Stoyanov
Telerik team
Lukasz
Top achievements
Rank 1
Iron
Share this question
or