Below is the class
public class ErrorDTO
{
public string Type { get; set; }
public string Data { get; set; }
}
I have list of ErrorDTO i.e List<ErrorDTO>
Below is the data
Type1 x
Type1 y
Type2 z
Type3 p
Type2 q
and so on....
I want to show this in a DataGrid of xaml in the following way
Type1 Type2 Type3
x z p
y q
How can I do this? I tried converting the list to a datatable but no luck.
invalidDataList is the List<ErrorDTO>
var r = invalidDataList
.Distinct()
.GroupBy(x => x.Type)
.Select(y => new { Type = y.Key, Data = y });
DataTable table = new DataTable();
foreach (var item in r)
{
table.Columns.Add(item.Type, typeof(string));
foreach (var i in item.Data)
{
DataRow dr = table.NewRow();
dr[item.Type] = i.Data;
table.Rows.Add(dr);
}
}
dataGrid.ItemsSource = table.AsEnumerable();