Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Linq Result to datagridview

Tags:

c#

linq

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

like image 449
usr021986 Avatar asked May 30 '11 09:05

usr021986


2 Answers

Try the following:

dataGridView.DataSource = groups.ToList();
like image 182
Akram Shahda Avatar answered Oct 15 '22 03:10

Akram Shahda


updated

Have you tried this way?

yourGridView.DataSource=groups.ToList();
yourGridView.DataBind();

for WinForm apps only do this:

yourGridView.DataSource=groups.ToList();
like image 5
danyolgiax Avatar answered Oct 15 '22 04:10

danyolgiax