How to Populate Data in the ListView Using XML File and C#

In this tutorial, I will teach you how to Populate Data in the ListView Using XML File and C#. This method has the ability to display the data from XML File to the ListView. This program is so simple and you can make it in no time. Please follow the instructions below to see how it works.

Creating XML FIle

Go to solution explorer and right click the file name. After that select “Add” and hit “New Item”.
Choose the “XML File” and named it “XMLFile1” then click “Add”.
Add data to the XML File.

<NewDataSet>

<person>

<Name>Janno Palacios</Name>

<Address>Kabankalan City</Address>

</person>

<person>

<Name>Jeanniebe Palacios</Name>

<Address>Kabankalan City</Address>

</person>

<person>

<Name>Craig Palacios</Name>

<Address>Kabankalan City</Address>

</person>

<person>

<Name>Kenjie Palacios</Name>

<Address>Kabankalan City</Address>

</person>

</NewDataSet>

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#.

Step 2

Add a ListView inside the Form just like shown below.

Step 3

Put the XML File in the resources folder by dragging it.

Step 4

Press F7 to open the code editor. In the code editor, create a method to get the data in the XML File and display it into the ListView.

Step 5

Write the following code to execute the method that you have created in the first load of the form.

privatevoid Form1_Load(object sender, EventArgs e)

{

LoadPerson(listView1);

}

The complete source code is included. You can download it and run it on your computer.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below.