Datagrid does not create columns when itemssource is Queryable or Enumrable on some computers
for this example, my computer generates automatic columns, but in other machines, the columns are not generated if the source is Queryable or Enumrable.
what could be different
public MainWindow()
{
InitializeComponent();
dg.DataContext = GetPaople();
}
public object GetPaople()
{
List<Person> list = new List<Person>();
for (int i = 0; i < 15; i++)
{
list.Add(new Person() { FirstName = "F" + i, LastName = "L" + i, Id = i });
}
var res = from p in list select p;
return res.AsQueryable();//not Genrating Columns
return list;//Genrating Columns
}
+3
source to share
1 answer
I don't think WPF DataGrid goes well with IQueryable collections. res.AsQueryable()
Try instead res.ToList()
.
By using ToList (), you are forcing the query to be evaluated and the results will be dumped into a list, which in this case will be strongly typed and can be checked by the DataGrid to generate columns.
+1
source to share