I'm programming in
VB, using Visual Studio 2008.
This is a Windows Forms program.
GOAL: I want to populate a multi column ListView with the <Name>, <Calories>, and <Fat> of each <Food> listed under a certain <Profile>.<Date>.<Name> from an xml file when I click
Button1. I've accomplished this using Excel spreadsheets as my data source, but now I want to use xml files for flexibility and portability.
Objects I'm using:
Here is my xml file (Foods.xml):
Code:
<?xml version="1.0" encoding="utf-8"?>
<Profiles>
<Profile>
<Name>Kelly</Name>
<Date>
<Name>Thursday: April 05, 2010</Name>
<Food>
<Name>Burger</Name>
<Calories>100</Calories>
<Fat>10</Fat>
</Food>
</Date>
</Profile>
<Profile>
<Name>Brandon</Name>
<Date>
<Name>Thursday: April 08, 2010</Name>
<Food>
<Name>Fries</Name>
<Calories>100</Calories>
<Fat>10</Fat>
</Food>
</Date>
</Profile>
</Profiles>
I don't even know where to begin with ListViews ... most of the online help seems to be for earlier versions of
VB, and VisualStudio 2008 is telling me that ".AddItem" is invalid syntax for ListView1.
Anyone out there smarter than me?
Here are my latest attempts:
Code:
ListBox1.ObjectCollection.AddRange(New Object() {"System.Xml"})
Code:
Dim Profiles As XDocument = XDocument.Load("Profiles.xml")
ListView1.Items.AddRange(New ListViewItem(Profiles.<Profile>.<Name>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray()))
Code:
ListView1.Items.AddRange(New ListViewItem() {Profiles.<Profile>.<Name>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())})