Bind Linq Result for datagridview

I have linq result like var and query as below

     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 a datagridview.

Please suggest

thank

+4
source share
3 answers

Try the following:

dataGridView.DataSource = groups.ToList();
+11
source

updated

Have you tried this way?

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

for WinForm applications, only this:

yourGridView.DataSource=groups.ToList();
+5
source

try it

    var groups = (myDataTable.AsEnumerable()
                  .GroupBy(r => r.Field<string>("X"))
                  .Select(g => new { Name = g.Key,Count=g.Count() })).ToList();
gridview1.DataSource=groups;
+1
source

All Articles