Solved

How do I bind the results to a grid

Posted on 2016-11-10
3
48 Views
Last Modified: 2016-11-10
  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
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41883005
Try it this way.

dataGridView1.DataSource = results.ToList();
0
 
LVL 81

Author Closing Comment

by:David Johnson, CD, MVP
ID: 41883035
works for me. Thanks
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41883086
Not a problem David, glad I was able to help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question