I have a simple code first database that I want to load on demand within a hierarchial grid. I have everythign working except I don't know how to cast the results within the RowSourceNeed procedure.
I setup the child template thusly:
Then in the radGridView2_RowSourceNeeded event when I open the row
private void radGridView2_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{ e.ParentRow.DataBoundItem as ??? }
I can see when I run it that e.ParentRow.DataBoundItem is a System.Data.Entity.DynamicProxies.Category_485959... type
See attached.
and that if I could just access the.Products of it then I could iterate and add the rows.
Any ideas how to access? Thanks.
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
}
public class Category
{
private readonly ObservableListSource<
Product
> _products =
new ObservableListSource<
Product
>();
public int CategoryId { get; set; }
public string Name { get; set; }
public virtual ObservableListSource<
Product
> Products { get { return _products; } }
}
public class ProductContext : DbContext
{
public DbSet<
Category
> Categories { get; set; }
public DbSet<
Product
> Products { get; set; }
public ProductContext()
: base("my conn string")
{
this.Configuration.AutoDetectChangesEnabled = true;
}
I setup the child template thusly:
this.radGridView2.RowSourceNeeded += new Telerik.WinControls.UI.GridViewRowSourceNeededEventHandler(this.radGridView2_RowSourceNeeded);
GridViewTemplate childTemplate = new GridViewTemplate();
childTemplate.HierarchyDataProvider = new GridViewEventDataProvider(childTemplate);
childTemplate.DataSource = this.productsBindingSource;
childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView2.MasterTemplate.Templates.Add(childTemplate);
Then in the radGridView2_RowSourceNeeded event when I open the row
private void radGridView2_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{ e.ParentRow.DataBoundItem as ??? }
I can see when I run it that e.ParentRow.DataBoundItem is a System.Data.Entity.DynamicProxies.Category_485959... type
See attached.
and that if I could just access the.Products of it then I could iterate and add the rows.
Any ideas how to access? Thanks.