简体   繁体   English

如何将 JSON 数据源绑定到 Dev Express DataGridView Itemsource 属性?

[英]How to Bind JSON data source to Dev Express DataGridView Itemsource property?

I have json data as api response and I want to bind it to Itemsource property of Dev express Datagridview.我有 json 数据作为 api 响应,我想将它绑定到 Dev express Datagridview 的 Itemsource 属性。

string json = "[{"prop1":"xxx1","prop2":"xxx2","prop3":"xxx3","prop4":"xxx4"},{"prop1":"yyy1","prop2":"yyy2","prop3":"yyy3","prop4":"yyy4"}]"

Since the json response can have different fields based on the api request, I cannot create strongly typed class and deserialize the response.由于 json 响应可以根据 api 请求具有不同的字段,因此我无法创建强类型类并反序列化响应。

So as per above json there will be columns prop1, prop2, prop3, prop4 and its data will be 2 rows.因此,根据上面的 json,将有 prop1、prop2、prop3、prop4 列,其数据为 2 行。

Things I have tried.我尝试过的事情。

myDataGrid.ItemsSource = JsonConvert.DeserializeObject(json1);

It generates two blank rows (for two records) somehow not able to display row data.它生成两个空白行(用于两个记录)以某种方式无法显示行数据。

Other things I have tried我尝试过的其他事情

myDataGrid.ItemsSource = JsonConvert.DeserializeObject<dynamic>(json1);

It generates two blank rows (for two records) somehow not able to display row data.它生成两个空白行(用于两个记录)以某种方式无法显示行数据。

Since the rows appears but no data displayed, its related to columns由于出现了行但没有显示数据,因此它与列有关

set the AutoGenerateColumnsMode property to Auto may fix the problemAutoGenerateColumnsMode属性设置为 Auto 可能会解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM