As per my understanding, you want to display data on form...
So, what you have to do?
1) create new windows form project
2) add 4 labels and 4 texboxes; change their names to undertandable names, such as:
txtCompanyName, txtContactName, txtContactTitle, txtPhone
3) create custom class, for example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
public class Customer
{
private string sCompanyName = string.Empty;
private string sContactName = string.Empty;
private string sContactTitle = string.Empty;
private string sPhone = string.Empty;
public Customer()
{
}
public Customer(string _CompanyName, string _ContactName, string _ContactTitle, string _Phone)
{
sCompanyName = _CompanyName;
sContactName = _ContactName;
sContactTitle = _ContactTitle;
sPhone = _Phone;
}
public void LoadFromXml(string sFileName)
{
XDocument xDoc = XDocument.Load(sFileName);
sCompanyName = xDoc.Root.Descendants().Where(n => n.Name == "CompanyName").Select(n => n.Value).FirstOrDefault();
sContactName = xDoc.Root.Descendants().Where(n => n.Name == "ContactName").Select(n => n.Value).FirstOrDefault();
sContactTitle = xDoc.Root.Descendants().Where(n => n.Name == "ContactTitle").Select(n => n.Value).FirstOrDefault();
sPhone = xDoc.Root.Descendants().Where(n => n.Name == "Phone").Select(n => n.Value).FirstOrDefault();
}
public string CompanyName
{
get { return sCompanyName; }
set { sCompanyName = value; }
}
public string ContactName
{
get { return sContactName; }
set { sContactName = value; }
}
public string ContactTitle
{
get { return sContactTitle; }
set { sContactTitle = value; }
}
public string Phone
{
get { return sPhone; }
set { sPhone = value; }
}
}
4) Now, add this code into Form1 class:
public partial class Form1 : Form
{
Customer oCust = new Customer();
public Form1()
{
InitializeComponent();
string sFile = @"FullFileName.xml";
oCust.LoadFromXml(sFile);
this.txtCompanyName.Text = oCust.CompanyName;
this.txtContactName.Text = oCust.ContactName;
this.txtContactTitle.Text = oCust.ContactTitle;
this.txtPhone.Text = oCust.Phone;
}
Note: it's just -
very basic - example! You can edit data, but nothing will be saved into xml. You need to provide method to change
oCust
object and save data into xml.
I'd suggest to read about:
1)
XmlSerialization and XmlDeserialization[
^] to be able to serialize xml to object and back to xml.
2)
DataBindings[
^]
Try!