Question

I have a problem in binding RadTreeView element to datasource, actually in setting ValueMember. Simplified, there are:

Model:

/// Parent
public class EmfLocation 
{
    public int ID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<EmfDataSet> EmfDataSets { get; set; }
}

/// Child
public class EmfDataSet
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int EmfLocationID { get; set; }
}

View:

/// treeDataset = new Telerik.WinControls.UI.RadTreeView();

private void GetTreeData()
{
    IList<EmfLocation> locationList = new List<EmfLocation>();
    locationList = repoEmfLocation.GetBy(testingId).ToList();

    treeDataset.DataSource = locationList;
    treeDataset.DisplayMember = "Name\\Name";
    treeDataset.ChildMember = "locationList\\EmfDataSets";
    treeDataset.ValueMember = "ID\\ID";
}

Everything works fine, value member for root nodes is set ok, but for child nodes (EmfDataSet) instead of value there is an "TargetInvocationException":

"Property accessor 'ID' on object 'System.Data.Entity.DynamicProxies.EmfDataSet_5F54359CCE6567583EDAE4FA2B61B7D274184C3985DAC9FE14B234AFFEE42F1B' threw the following exception:'Object does not match target type.'"

What is wrong?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top