Reputation: 3511
i have a linq result as var & query as following
var groups = myDataTable.AsEnumerable()
.GroupBy(r => r.Field<string>("X"))
.Select(g => new { Name = g.Key,Count=g.Count() });
I want to bind the result to datagridview.
Please suggest
Thanks
Upvotes: 5
Views: 27830
Reputation: 13086
updated
Have you tried this way?
yourGridView.DataSource=groups.ToList();
yourGridView.DataBind();
for WinForm apps only do this:
yourGridView.DataSource=groups.ToList();
Upvotes: 5
Reputation: 2215
Try this
var groups = (myDataTable.AsEnumerable()
.GroupBy(r => r.Field<string>("X"))
.Select(g => new { Name = g.Key,Count=g.Count() })).ToList();
gridview1.DataSource=groups;
Upvotes: 1
Reputation: 14771
Try the following:
dataGridView.DataSource = groups.ToList();
Upvotes: 14