【问题标题】:Show data in DevExpress Grid from JSON format在 DevExpress Grid 中显示 JSON 格式的数据
【发布时间】:2021-07-28 04:40:52
【问题描述】:

我有一个 JSON 格式的数据,需要在网格控件中显示。该 JSON 数据如果有一个数组,那么它会在网格中正确显示,并带有 (+) 号以展开,但如果它有一个具有其成员的对象,那么它只会显示为具有其类 ID 的列。

如果类对象在数组中,则显示如下:

如果类对象只是单个对象,则显示如下:

我的 JSON 字符串如下:

[
    {
        "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"
        }
    }   
]

我已经在 Grid 中加载了字符串,如下所示:

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

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

gridControl1.DataSource = jsonDataSource;

如果数据仅在单个对象中接收,如何将带有 (+) 号的地址显示为扩展?

【问题讨论】:

    标签: c# devexpress xtragrid gridcontrol devexpress-windows-ui


    【解决方案1】:

    JsonDataSource 是什么?

    (+)号是Master-Detail Grid

    如果你想自定义细节网格,你必须处理MasterRowExpanded Event

    这篇文章可能会有所帮助:Working with Master-Detail Relationships in Code

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多