How do I bind the results to a grid

  private void button1_Click(object sender, EventArgs e)
        {
            var xdoc = XDocument.Load(@"..\..\Employees.xml");

            var results = from emp in xdoc.Root.Elements()
                          from child in emp.Elements()
                          select new
                          {
                              TagName = child.Name.LocalName,
                              Value = child.Value
                          };
            dataGridView1.DataSource = results;  // this obviously doesn't work
        }
    }
}

Open in new window


As shown in the answer @ https://www.experts-exchange.com/questions/28982335/c-code.html#a41882648

We all have to start learning somewhere
What I wantEmployees.xml
LVL 86
David Johnson, CD, MVPOwnerAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Try it this way.

dataGridView1.DataSource = results.ToList();
0
 
David Johnson, CD, MVPOwnerAuthor Commented:
works for me. Thanks
0
 
Fernando SotoRetiredCommented:
Not a problem David, glad I was able to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.