Hello,
I am am trying to get a ListView to populate based on an xml file.
to acheive this I would like to use the DataTable.
this is my XML file:
<?xml version="1.0"?>
<main>
<person>
<id>1</id>
<name><first>Joe</first><last>Blow</last></name>
</person>
</main>
And the C# that I am using to read it:
public mainForm()
{
InitializeComponent();
listView.View = View.Details;
FillList();
}
public static DataTable GetPeople()
{
DataSet dsStore = new DataSet();
dsStore.ReadXml("example.xml");
return dsStore.Tables["person"];
}
private FillList()
{
listView.Items.Clear();
DataTable dtPeople = GetPeople();
listView.BeginUpdate();
foreach (DataRow dr in dtPeople.Rows)
{
ListViewItem listItem = new ListViewItem(dr["id"].ToString());
listItem.ImageIndex = 0;
listItem.SubItems.Add(dr["name"].ToString());
listView.Items.Add(listItem);
}
if (listView.Columns.Count == 0)
{
listView.Columns.Add("ID", 100, HorizontalAlignment.Left);
listView.Columns.Add("Name", 100, HorizontalAlignment.Left);
}
listView.EndUpdate();
}
Alright, all this works, that is, without the "SubItems" part.
and that is my question.
The error i get is: Column 'name' does not belong to table person. (this is regarding the highlighted code that is in red)
Now, how would i be able to extract the name as a whole? (like i am trying to do in the example)
And also how would i be able to extract first and last names seperately?
Thanks a million in advance.