Shubhit304
Shubhit304

Reputation: 301

Show data in DevExpress Grid from JSON format

I have a JSON format data that I need to show in the grid control. That JSON data if having an array then it is getting shown properly in grid with (+) sign to expand, but if it has a single object that has its members, then it is just shown as column with its class ID.

If class object is in array then it is showing like this: enter image description here

If the class object is just a single object, then it is showing like this: enter image description here

My JSON string is as below:

[
    {
        "customerID" : "AROUT",
        "companyName" : "Around the Horn",
        "contactName" : "Thomas Hardy",
        "contactTitle" : "Sales Representative",
        "address" : {
            "street" : "120 Hanover Sq.",
            "city" : "London",
            "region" : "NULL",
            "postalCode" : "WA1 1DP",
            "country" : "UK",
            "phone" : "(171) 555-7788"
        }
    },
    {
        "customerID" : "BERGS",
        "companyName" : "Berglunds snabbköp",
        "contactName" : "Christina Berglund",
        "contactTitle" : "Order Administrator",
        "address" : {
            "street" : "Berguvsvägen  8",
            "city" : "Luleå",
            "region" : "NULL",
            "postalCode" : "S-958 22",
            "country" : "Sweden",
            "phone" : "0921-12 34 65"
        }
    },
    {
        "customerID" : "BLAUS",
        "companyName" : "Blauer See Delikatessen",
        "contactName" : "Hanna Moos",
        "contactTitle" : "Sales Representative",
        "address" : {
            "street" : "Forsterstr. 57",
            "city" : "Mannheim",
            "region" : "NULL",
            "postalCode" : 68306,
            "country" : "Germany",
            "phone" : "0621-08460"
        }
    }   
]

And I have loaded the string in Grid as below:

string jsonString = File.ReadAllText(@"D:\Data.txt");            

JsonDataSource jsonDataSource = new JsonDataSource();
jsonDataSource.JsonSource = new CustomJsonSource(jsonString);
jsonDataSource.Fill();

gridControl1.DataSource = jsonDataSource;

So how to show the address with (+) sign as expansion if data is receiving in single object only?

Upvotes: 0

Views: 1464

Answers (1)

我零0七
我零0七

Reputation: 493

what's JsonDataSource?

the (+)sign is Master-Detail Grid

If you want to custom detail grid,you must handle MasterRowExpanded Event.

this article may be helpful:Working with Master-Detail Relationships in Code

Upvotes: 0

Related Questions