How to add XML Data to DataGridView using C#



If you've enjoyed reading this post then please subscribe to my Full Text RSS Feed.

This is an example on how to upload the content of a XML file into a DataGridView using Windows Form. First, we create a Windows project in Visual Studio and design the form like the one shown below. Controls to add:

FileUpload control
DataGridView control
Button control


When you run the application and select a XML file using the “Browse” button, the data is taken from the XML file and bound to the DataGridView as shown below.

The Button1_Click event loads the xml content into a DataSet (in this example called ds). Then the Dataset, ds is bound to the DataGridView (dataGridView1).

dataGridView1.DataSource = ds;
dataGridView1.DataMember = “G_EMC_MODEL”;
(“G_EMC_MODEL” is the xml node and all the child node of G_EMC_MODEL is bound to dataGridView1).

The DataXML method as shown below opens the XML file using System.IO.FileStream stream. And the DataSet’s ReadXML method reads the content of the XML file into the DataSet.

That is how simple it is to bind a XML file data to a DataGridView.

Sphere: Related Content

Related Posts

About the Author

a tech junkie and a software developer. a apple fan and an avid photographer. a frequent traveller and loves art and graphic novels. My Google+