Unable to feed Treeview with entities

Hi there, I have an MS SQL table from which I derive an Entity Framework DbSet. 
Specifying the DbSet as the TreeView's DataSource results in an error.
If I convert this DbSet to a List or IEnumerable, TreeView remains blank.
Converting the DbSet to an array, a series of empty root nodes appear.
Please advise.

Example Data: (TreeView looks the same if restricted to these data):
PIR SupervisorPIR Name Alive
309271
EMBERI ERŐFORRÁSOK MINISZTÉRIUMA 1
308647 309271 EMBERI ERŐFORRÁSOK MINISZTÉRIUMA ASZÓDI JAVÍTÓINTÉZET, ÁLTALÁNOS ISKOLA, SZAKISKOLA ÉS SPECIÁLIS SZAKISKOLA 1
308636 309271 EMBERI ERŐFORRÁSOK MINISZTÉRIUMA BUDAPESTI JAVÍTÓINTÉZETE 1
308692 309271 EMBERI ERŐFORRÁSOK MINISZTÉRIUMA DEBRECENI JAVÍTÓINTÉZETE 1
840110 309271 EMBERI ERŐFORRÁSOK MINISZTÉRIUMA NAGYKANIZSAI JAVÍTÓINTÉZETE 0
308669 309271 EMBERI ERŐFORRÁSOK MINISZTÉRIUMA RÁKOSPALOTAI JAVÍTÓINTÉZETE ÉS KÖZPONTI SPECIÁLIS GYERMEKOTTHONA 1

Code:
               HuLexEntities huLexEntities = new HuLexEntities();
                CBI[] cbis = huLexEntities.CBIs.AsNoTracking().Where( d => d.PIR == "309271" || d.SupervisorPIR == "309271").ToArray();
                treeCbi.SelfRelationRootValue = "";
                treeCbi.DisplayMember = "Name";
                treeCbi.ParentMember = "SupervisorPIR";
                treeCbi.ChildMember = "PIR";
                treeCbi.ValueMember = "Name";
                treeCbi.CheckedMember = "Alive";
                treeCbi.DataSource = cbis;

Result: 

  

2 Replies 1 reply marked as answer

GG Gyorgy Gorog October 29, 2020 09:41 AM UTC

Hi, the same if I detach data from entities and provide an object array. 

private class SimpleCbi
        {
            public string Pir = string.Empty;
            public string ParentPir = string.Empty;
            public string Name = string.Empty;
            public bool IsAlive = false;
        }

List<SimpleCbi> cbis = new List<SimpleCbi>();
.... add data....

treeCbi.SelfRelationRootValue = "";
                treeCbi.DisplayMember = treeCbi.ValueMember = nameof( SimpleCbi.Name );
                treeCbi.ParentMember = nameof( SimpleCbi.ParentPir );
                treeCbi.ChildMember = nameof( SimpleCbi.Pir );
                treeCbi.CheckedMember = nameof( SimpleCbi.IsAlive );
                treeCbi.DataSource = cbis.ToArray();

It's interesting that at least when it's an array, something happens; nothing happens for a list.



VR Vijayalakshmi Roopkumar Syncfusion Team October 29, 2020 05:17 PM UTC

Hi Gyorgy 
 
Thank you for contacting Syncfusion Support. 
 
We have checked that the reported behaviour that Items are not populated properly in TreeviewAdv when it is bounded to list type of Items in our sample, and we could find that no items is visible and bounded with ArrayType too. Please find the code and sample below: 
 
Code:[C#] 
 
 
treeViewAdv1.DataRelations.Clear(); 
treeViewAdv1.DataMember = nameof(SimpleCbi.ContinentID); 
treeViewAdv1.DataRelations.Clear(); 
treeViewAdv1.DisplayMember = nameof(SimpleCbi.Name); 
treeViewAdv1.ParentMember = nameof(SimpleCbi.ContinentID); 
treeViewAdv1.ChildMember = nameof(SimpleCbi.CountryID); 
treeViewAdv1.ValueMember = nameof(SimpleCbi.Capital); 
treeViewAdv1.CheckedMember = nameof(SimpleCbi.IsAlive); 
treeViewAdv1.DataSource = dataTable1; 
treeViewAdv2.DataRelations.Clear(); 
treeViewAdv2.DataMember = "Continent"; 
treeViewAdv2.DataRelations.Clear(); 
treeViewAdv2.DisplayMember = nameof(SimpleCbi.Name); 
treeViewAdv2.ParentMember = nameof(SimpleCbi.ContinentID); 
treeViewAdv2.ChildMember = nameof(SimpleCbi.CountryID); 
treeViewAdv2.ValueMember = nameof(SimpleCbi.Capital); 
treeViewAdv2.CheckedMember = nameof(SimpleCbi.IsAlive); 
treeViewAdv2.DataSource = cbis.ToArray(); 
 
 
 
Screenshot shows one with Bounded with Array type and other with DataTable: 
 
 
 
 
 
So could you please check the sample and confirm us whether our replication on the reported behaviour is same with yours. If so, we will check further on this behaviour , however it is different could you modify our sample into issue reproducible or shows the sample that working fine with ArrayType , it would be very helpful for us to proceed on it further. 
 
Regards, 
Vijaaylakshmi VR 


Marked as answer
Loader.
Up arrow icon