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

Binding grid to collection of base type

1 Answer 14 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 14 Dec 2011, 06:44 PM
I have an issue similar to this post:
http://www.telerik.com/community/forums/silverlight/gridview/binding-itemssource-to-observablecollection-lt-baseclass-gt-causes-exception.aspx

Basically, I have base class, and 3 classes the inherit from the base class.  I bind the grid to a collection of items that is a mix of the inherited classes.  The grid is set up to only displays properties from the base class, however after binding, the columns do not display any data.  (and grouping by a column of the base class throws an error.

Below is a simplified version of what I am trying to do.  Is there anything I can do to get it to work?  I'm using version 2011.1.620.1040.
Thanks.
public class BaseClass
{
   public string Name { get; protected set; }
}
 
public class InheritedClass1 : BaseClass
{
  public InheritedClass1()
  {
    this.Name = "Class 1";
  }
}
 
public class InheritedClass2 : BaseClass
{
  public InheritedClass2()
  {
    this.Name = "Class 2";
  }
}
 
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
  List<BaseClass> list = new List<BaseClass>();
  list.Add(new InheritedClass1());
  list.Add(new InheritedClass1());
  list.Add(new InheritedClass2());
  list.Add(new InheritedClass2());
 
  gridView1.ItemsSource = list;
}

<telerik:RadGridView Name="gridView1" AutoGenerateColumns="False">
  <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" /> 
  </telerik:RadGridView.Columns>
</telerik:RadGridView>


1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Dec 2011, 08:06 AM
Hello,

 Can you try our latest official version (Q3 2011) instead? 

Best wishes,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or