Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Loading XML data into ListView control

Loading XML data into ListView control

Scheduled Pinned Locked Moved C#
xml
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I have googled for 2 days straight with no success... Scenario: Load simple xml data into listview control with 2 or more columns. I have used XmlTextReader and XmlReader with very limited success. I am able to populate the listview but only the first column. If someone could point me in the right direction, I would greatly appreciate it. --Steve

    B L 2 Replies Last reply
    0
    • L Lost User

      I have googled for 2 days straight with no success... Scenario: Load simple xml data into listview control with 2 or more columns. I have used XmlTextReader and XmlReader with very limited success. I am able to populate the listview but only the first column. If someone could point me in the right direction, I would greatly appreciate it. --Steve

      B Offline
      B Offline
      bit_cmdr
      wrote on last edited by
      #2

      I would suggest investigating how to create a DataTable and populate it with your xml. This will not be an easy task but it's by no means overly difficult either. It will just take a bit of work to accomplish. You will have to create each column in the DataTable and fill it with the appropriate data. Once that's done you can bind the DataTable to the ListView and you should be good to go. There may be a way to cut out the DataTable entirely but you may figure that out by researching what I suggested.

      - Arcond

      1 Reply Last reply
      0
      • L Lost User

        I have googled for 2 days straight with no success... Scenario: Load simple xml data into listview control with 2 or more columns. I have used XmlTextReader and XmlReader with very limited success. I am able to populate the listview but only the first column. If someone could point me in the right direction, I would greatly appreciate it. --Steve

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Go figure: I post my question and then I find my answer. Answer lies with XmlDocument. See code snippet below. My xml file (checklist.xml) is really an index used for parsing files of their data based on a starting point, string size, and a description. In turn these are my columns in my listview control as well. private void tsbtnRunAudit_Click( object sender, EventArgs e ) { XmlDocument xdoc = new XmlDocument(); xdoc.Load(@"C:\DEVELOPMENT\Sandbox\VikConvAudit\VikConvAudit\Indexes\checklist.xml"); XmlNodeList start = xdoc.GetElementsByTagName("Start"); XmlNodeList size = xdoc.GetElementsByTagName("Size"); XmlNodeList description = xdoc.GetElementsByTagName("Description"); for(int i = 0; i < start.Count; i++) { lvMain.Items.Add(start[i].InnerText); lvMain.Items[i].SubItems.Add(size[i].InnerText); lvMain.Items[i].SubItems.Add(description[i].InnerText); } }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups