This question is locked. New answers and comments are not allowed.
public abstract class ViewModel
{ public string Name{get;set;} public ViewType Type {get;set;} }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