Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2010, 10:51 AM
Registered User
 
Join Date: Apr 2010
Posts: 21
Thanks: 12
Thanked 0 Times in 0 Posts
Send a message via AIM to QuadFather
Unhappy How to populate ListView with XML data?

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:
  • ListView1
  • Button1

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())})

Last edited by QuadFather; April 12th, 2010 at 10:52 AM.. Reason: typo





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to populate listbox with xml data: VB2008 QuadFather XML 4 April 12th, 2010 10:43 AM
How to populate combobox with xml using VB? QuadFather XML 8 April 7th, 2010 09:07 AM
Populate ListView From ComboBox Select eusanpe C# 4 August 20th, 2007 06:49 PM
how to populate a table with xml data in xslt miccipynewbie XSLT 6 May 28th, 2007 07:29 AM
Populate Listview yves VB Databases Basics 1 February 6th, 2006 08:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.