Binding XML file to a ListBox Using C#
Now, here’s another tutorial that you’ll surely want to learn. By this time, I’m going to teach you how to bind an XML file to a listbox using C#. By using this method you will be able to control the connection between XML file and the listbox. It also has the ability to view the content of XML file in the listbox.
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” then click “Add”.
Add data to the XML File.
- <Description>Belgium Francs</Description>
- <Description>Germany Deutsche Marks</Description>
- <Description>Spain Pesetas</Description>
- <Description>France Francs</Description>
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.
Add a ListBox inside the Form just like shown below.
Put the XML File in the resources folder by dragging it.
Press F7 to open the code editor. In the code editor, create a method to retrieve the data in the ListBox.
Write the following code to execute the method that you have created in the first load of the form.
- private void Form1_Load(object sender, EventArgs e)
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.