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

[Solved] Error when grouping on Abstract Type

2 Answers 101 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.
Carson
Top achievements
Rank 1
Carson asked on 18 Aug 2011, 08:35 PM
public abstract class ViewModel
{
    public string Name{get;set;}
    public ViewType Type {get;set;}
  
}
The Above Class is the my base view model that is being displayed in the grid.

I derive several other VM from this one and Bind a grid to them

public class PersonViewModel:ViewModel
{
  public string State{get;set;}
}
  
public class AddressViewModel:ViewModel
{
  public string Street1{get;set;}
}

ObservableCollection<ViewModel> _items;
  
public ObservableCollection<ViewModel>
{
  get
  {
    return _items;
  }
}

The Grid is then bound to the Items property

<GridView:RadGridView 
              ItemsSource="{Binding Items}" 
              CanUserFreezeColumns="False" 
              ScrollMode="RealTime" 
              IsReadOnly="True" 
              x:Name="AlertGrid" IsFilteringAllowed="False"
              GridLinesVisibility="None" AutoGenerateColumns="False"
              MinHeight="350" MaxHeight="525"
              RowStyle="{StaticResource rowStyle}">
              <GridView:RadGridView.Columns>
                  <GridView:GridViewDataColumn Header="Name" SortingState="Descending" DataMemberBinding="{Binding Name}" Width="150" IsFilterable="False"/>
                  <GridView:GridViewDataColumn Header="ViewType" DataMemberBinding="{Binding Type}" Width="150" IsFilterable="False"/>
                       </GridView:RadGridView.Columns>
          </GridView:RadGridView>

When I first load the ites everything in the collection are just PersonViewModel and they display fine. If I group on a property of the base type i.e. ViewModel.Name It will group just fine. However if while grouped I add a new item to the collection that is an AddressViewModel then I get an exception that looks like

The value "AddressViewModel" is not of type "PersonViewModel" and cannot be used in this generic collection.

If I however ungroup the grid and then add the AddressViewModel to the collection and then regroup, it all works as expected and I don't recieve an error.

Understand that my problem has been paraphrased and these are not the exact object names nor fields that I am using in the application, but hopefully describes my problem well enough.

I am using 2011.2.712.1040 of the Grid Controls

2 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 22 Aug 2011, 01:46 PM
Hi Carson,

We've identified the issue and we will look for a way to resolve it. We will let you know when we have more information regarding this issue. Thank you for your understanding.

Regards,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Rossen Hristov
Telerik team
answered on 31 Aug 2011, 11:43 AM
Hello Carson,

I think that I managed to fix the problem.

I am attaching a sample project which uses a "preview" build of our assemblies for testing purposes. The fix will be released with our "Latest Internal Build" coming out next Monday. The official release will be with SP1 coming out in mid-September.

Please, test your most common use cases with the "preview" build that I have provided and let me know if you manage to find another problem. In this way, I will have more time to react and fix it before the official SP1 comes out in mid-September.

Thank you for your cooperation.

Kind regards,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

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