简体   繁体   English

如何绑定到集合的集合以在DataGrid上显示信息?

[英]How to bind to a collection of collections to display informationon a DataGrid?

I'm trying to bind a List<List<string>> to a DataGrid programatically. 我试图以编程方式将List<List<string>>绑定到DataGrid I'm using this List<List<string>> because the DataGrid has to have a variable number of columns. 我正在使用此List<List<string>>因为DataGrid必须具有可变数量的列。

Actually, I got to bind the DataGrid to an string[][] but it is partially useful because there will be the need to get this data structure and add rows to it, that's why I want to use a List<List<string>> . 实际上,我必须将DataGrid绑定到一个string[][]但这部分有用,因为将需要获取此数据结构并向其中添加行,这就是为什么我要使用List<List<string>>

Currently, I'm using this snippet to generate the columns. 目前,我正在使用此代码段生成列。

dgResults.Columns.Clear();
for (int i = 0; i < numColumns; i++)
{
    DataGridTextColumn textColumn = new DataGridTextColumn();
    textColumn.Binding = new Binding(string.Format("[{0}]", i));
    dgResults.Columns.Add(textColumn);
}

What should I use on textColumn.Binding in order to bind to a List<list<string>> ? 我应该在textColumn.Binding上使用什么才能绑定到List<list<string>>

哇...我使用的是string[][]结构...但是使用我编写的代码段, List<List<string>>可以用于预期的目的!

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

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