Manually fill datagrid from 2-dimensional string array

Oct 13, 2008 at 9:37 PM
I have a 2-dimensional string array (List<List<string>>) and want to fill the datagrid. How is this possible in code (C#). Thanks!
Coordinator
Oct 22, 2008 at 2:48 PM
You can possibly do something like this (assuming that each sublist has the same number of items):

List

 

<List<string>> tempList = new List<List<string>>
    {
        new List<string> { "vince", "elizabeth", "brian", "mark" },
        new List<string> { "vince2", "elizabeth2", "brian2", "mark2" },
        new List<string> { "vince3", "elizabeth3", "brian3", "mark3" },
        new List<string> { "vince4", "elizabeth3", "brian3", "mark4" },
    };

for
(int i=0; i<tempList[0].Count; i++)
{
    DataGrid_Standard.Columns.Add(
new DataGridTextColumn
        {
            Header = i,
            DataFieldBinding =
new Binding("[" + i + "]")
        });
}
DataGrid_Standard.ItemsSource = tempList;