Current filter:
                                You should refresh the page.
                                  • I would like to bind unknown JSON using DynamicObject to a GridControl.

                                    I am attaching a sample that I made..

                                    1. GridControl bound to dynamic directly - works but children don't show
                                    2. GridControl bound to Dynamic Object - records populate but columns/fields do not.
                                    3. GridControl bound to Dynamic Object with INotifyPropertyChanged and ICustomTypeDescriptor - records populate but columns/fields do not.

                                    How do I get #2 or #3 working?

                                1 Solution

                                Creation Date Importance Sort by

                                Hello,
                                Our data aware controls (DataGrid, TreeList etc.) support binding to data sources listed in Traditional Data Binding Methods.
                                 

                                1. At runtime, dynamic is resolved to a list of JObjects. JObject in turn doesn't contain a public property of a collection type to extract data from. As a result, details cannot be extracted and displayed.
                                 
                                To populate columns, GridControl either obtains the type of the objects stored in the underlying data source and creates columns taking all visible and writable properties or uses ITypedList.

                                2 and 3. Neither DynamicObjectTest and DynamicObjectWithBindingTest contain any properties which correspond to the fields nor are these objects stored in an ITypedList. So, it is expected that their properties aren't displayed.
                                 
                                To achieve the required result, I would recommend you avoid using the DynamicObject approaches and use a strongly typed approach instead. For instance, you can declare a class and map your Json data to it:
                                 

                                [C#]
                                public class MyClass { public int Id { get; set; } public string Name { get; set; } public BindingList<MyClass> ChildObjects { get; set; } }

                                Alternatively, consider using UnboundSource - a component designed for data binding scenarios when no strongly typed data set is available.
                                 
                                 
                                Please also note that starting with the upcoming version, 19.2, you can use JsonDataSource that allows you to extract JSON data from a Web-service endpoint, text file or JSON string. Refer to Bind to JSON Data for precise steps on how to configure a JSON data connection for data-aware controls that support the Data Source Configuration Wizard.

                                Show all comments
                                • GregDev 09.09.2019

                                  Thanks Stas, after implementing ITypedList and IRelationList I was able to get all my unstructured JSON to bind to the grid correctly... it seemed like I needed to implement IRelationList, merely putting an array of child records in the main record didn't cause it to display as a child record.

                                    Greg

                                • Stas (DevExpress Support) 09.10.2019

                                  Implementing IRelationList is one of the possible ways to supply detail data, but not the only one. GridControl can automatically recognize details which reside in a public collection property at the class level. Refer to the code in my answer for the implementation.
                                   
                                  If you observe different results, would you please share a sample project demonstrating your implementation so we can research it and provide you with a precise solution?

                                • GregDev 09.10.2019

                                  Sure.. here is an updated example showing IRelationList binding working on the top, and the bottom is bound without it using a bindinglist for the child collection.

                                  I made a function to walk the objects and dump their types and values to the debug window when you run it (output below).  It's entirely possible I have a bug that's preventing this from working but I just don't see it.

                                  [C#]
                                  Contents of Dynamic Binding List --------------- 1: Key:id Type:Newtonsoft.Json.Linq.JValue Value:1 Key:name Type:Newtonsoft.Json.Linq.JValue Value:bob dob 2: Key:id Type:Newtonsoft.Json.Linq.JValue Value:2 Key:name Type:Newtonsoft.Json.Linq.JValue Value:joe smith Key:children Type:TestJsonBinding.DynamicBindingList Value: 1: Key:id Type:Newtonsoft.Json.Linq.JValue Value:1 Key:name Type:Newtonsoft.Json.Linq.JValue Value:bob dob 2: Key:id Type:Newtonsoft.Json.Linq.JValue Value:2 Key:name Type:Newtonsoft.Json.Linq.JValue Value:joe smith
                                • Stas (DevExpress Support) 09.11.2019

                                  Please note when GridControl is bound to a collection of objects, it generates details based on public properties of a collection type declared at the data object level. In your project though, the DynamicObjectTest class doesn't contain any public properties of a collection type. That is why details aren't displayed when binding to DynamicBindingList.

                                • GregDev 09.11.2019

                                  Stas, thanks for your help.. as a test I tried adding this test class:

                                      public class TestClass
                                      {
                                          public string testproperty { get { return "hit there"; } }
                                      }

                                  Then added this public property to DynamicObjectTest:

                                  public List<TestClass> TestChildren { get; set; }

                                  In the constructor I added:

                                                  TestChildren = new List<TestClass>();
                                                  TestChildren.Add(new TestClass());
                                                  TestChildren.Add(new TestClass());

                                  But I still don't see the option to expand the child records?

                                • Stas (DevExpress Support) 09.12.2019

                                  I see DynamicBindingList implements ITypedList those implementation doesn't return the TestChildren property.
                                  Check whether this property is returned from ITypedList.GetItemProperties and let me know your results.

                                • GregDev 09.12.2019

                                  Stas, I double checked and I did have a bug where it was not including this property.  I fixed it and added the properties to the debugging output.  Now I see this but still no child records in the UI. I am also attaching the updated test project.

                                  [C#]
                                  Contents of Dynamic Binding List --------------- 1: Key:id Type:Newtonsoft.Json.Linq.JValue Value:1 Key:name Type:Newtonsoft.Json.Linq.JValue Value:bob dob Properties: 1. "id" (System.Int64) 2. "name" (System.String) 3. "children" (TestJsonBinding.DynamicBindingList) 4. "TestChildren" (System.Collections.Generic.List`1[TestJsonBinding.TestClass]) 2: Key:id Type:Newtonsoft.Json.Linq.JValue Value:2 Key:name Type:Newtonsoft.Json.Linq.JValue Value:joe smith Key:children Type:TestJsonBinding.DynamicBindingList Value: 1: Key:id Type:Newtonsoft.Json.Linq.JValue Value:1 Key:name Type:Newtonsoft.Json.Linq.JValue Value:bob dob Properties: 1. "id" (System.Int64) 2. "name" (System.String) 3. "TestChildren" (System.Collections.Generic.List`1[TestJsonBinding.TestClass]) 2: Key:id Type:Newtonsoft.Json.Linq.JValue Value:2 Key:name Type:Newtonsoft.Json.Linq.JValue Value:joe smith Properties: 1. "id" (System.Int64) 2. "name" (System.String) 3. "TestChildren" (System.Collections.Generic.List`1[TestJsonBinding.TestClass]) Properties: 1. "id" (System.Int64) 2. "name" (System.String) 3. "children" (TestJsonBinding.DynamicBindingList) 4. "TestChildren" (System.Collections.Generic.List`1[TestJsonBinding.TestClass])
                                • GregDev 09.12.2019

                                  Oh hang on I think I have another bug with ITypedList ... 

                                • GregDev 09.12.2019

                                  I tried making a simpler version of the issue without the dynamic JSON and that worked great.. then when I went back to the dynamic classes they were working too so I must have fixed a typo somewhere without realizing it.

                                  Anyways.. here is the working code thanks for your help.   Top binds using IRelation .. bottom binds it all at once.

                                  Thanks so much for your help.