如何将DevExpress Grid绑定到Dictionary

时间:2016-10-05 20:05:52

标签: grid devexpress

我有一个字典键值对

Dictionary<string, string> Details
Details.Add("Name","ABC");
Details.Add("Number","1234");

如何将其添加为devexpress网格的数据源(标题较少),以便网格显示

Col1 Col2

名称ABC

编号1234

解决一些道路

1 个答案:

答案 0 :(得分:1)

您可以使用以下方法:

gridControl1.DataSource = new Dictionary<string, string> { 
    { "Name", "Abc" },
    { "Number", "1234" },
    // ...
};
var gridView = gridControl1.MainView as GridView;
gridView.PopulateColumns();
gridView.Columns["Key"].Caption = "Col1";
gridView.Columns["Value"].Caption = "Col2";