• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 84
  • Last Modified:

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
David Johnson, CD, MVP
David Johnson, CD, MVP
  • 2
1 Solution
Fernando SotoRetiredCommented:
Try it this way.

dataGridView1.DataSource = results.ToList();
David Johnson, CD, MVPOwnerAuthor Commented:
works for me. Thanks
Fernando SotoRetiredCommented:
Not a problem David, glad I was able to help.
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.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now