1 Replies - 444 Views - Last Post: 02 May 2013 - 02:44 AM Rate Topic: -----

#1 DaedalusAero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 04-July 12

Populate treeView from XML data file

Posted 02 May 2013 - 02:04 AM

I have the following XML data file (this is just a sample) which gets populated programatically when other xml documents are loaded into my program.

<DMs>
  <dataModule>
    <DMC>DMC-AJ-A-21-21-63-00ZZZ-254Z-B_001-00.XML</DMC>
    <techName>Filter assy - blowing</techName>
    <infoName>Clean mechanically</infoName>
    <system>65</system>
    <subsystem>32</subsystem>
    <subsubsystem>12</subsubsystem>
    <status>Checked In</status>
    <notes>-</notes>
    <currentUser>-</currentUser>
    <validator>-</validator>
    <dateMod>-</dateMod>
    <size>-</size>
  </dataModule>
  <dataModule>
    <DMC>DMC-xx-A-21-21-63-00ZZZ-041Z-D_001-00.XML</DMC>
    <techName>Filter assy</techName>
    <infoName>Description of how it is made</infoName>
    <system>21</system>
    <subsystem>15</subsystem>
    <subsubsystem>63</subsubsystem>
    <status>Checked In</status>
    <notes>-</notes>
    <currentUser>-</currentUser>
    <validator>-</validator>
    <dateMod>-</dateMod>
    <size>-</size>
  </dataModule>
  <dataModule>
    <DMC>DMC-xx-A-21-21-63-00ZZZ-042Z-D_001-00.XML</DMC>
    <techName>Filter assy - blowing</techName>
    <infoName>Description of function</infoName>
    <system>21</system>
    <subsystem>15</subsystem>
    <subsubsystem>63</subsubsystem>
    <status>Checked In</status>
    <notes>-</notes>
    <currentUser>-</currentUser>
    <validator>-</validator>
    <dateMod>-</dateMod>
    <size>-</size>
  </dataModule>
  <dataModule>
    <DMC>DMC-xx-A-21-21-63-00ZZZ-066Z-D_001-00.XML</DMC>
    <techName>Filter assy - blowing</techName>
    <infoName>Support equipment and tools data</infoName>
    <system>32</system>
    <subsystem>10</subsystem>
    <subsubsystem>01</subsubsystem>
    <status>Checked In</status>
    <notes>-</notes>
    <currentUser>-</currentUser>
    <validator>-</validator>
    <dateMod>-</dateMod>
    <size>-</size>
  </dataModule>
</DMs>


What i want to be able to do is create a treeView hierachy in my Windows application which displays the "system", "subsystem" and "subsubsystem" elements of the XML file. I want to be able to drill down through the treeView to display the breakdown of all the documents. So in the first case above i would click on system 65, which would show that there is a document which has a subsystem of 32, and a subsubsystem of 12.

There will be many instances in the XML data file where there are documents that have the same "system" or "subsystem" etc. elements (becasue they belong to the same system like in the second and third entries in the above xml sample), so i don't want these to be repeated in my treeView. I need a treeView containing all the system, subsystem and subsubsystem numbers in the xml data file, but not repeating itself.

I've got the following method which I think i'm going in the right direction with, but it's getting the system numbers into a collection and sorting them to pass to my method which i'm struggling to know how to do.

public void buildTreeView(string sys, string subsys, string subsubsys)
        {
            try
            {
                TreeNode system = treeView1.Nodes.Add("System");
                system.Nodes.Add(sys);
                TreeNode subsystem = system.Nodes.Add("Subsystem");
                subsystem.Nodes.Add(subsys);
                TreeNode subsubsystem = subsystem.Nodes.Add("Subsubsystem");
                subsubsystem.Nodes.Add(subsubsys);
            }
            catch (Exception e)
            {
                MessageBox.Show("error" + e);
            }

        }


What i'm looking to end up with is a chapter numbering system that i can drill down though in the treeView within my Windows form i.e.

+ System - 65
        + Subsystem - 32
          Subsystem - 68
                       + Subsubsystem - 01
                         Subsubsystem - 02

+ System - 70
        + Subsystem - 22
          Subsystem - 30
                       + Subsubsystem - 01


Any pointers appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Populate treeView from XML data file

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 359
  • View blog
  • Posts: 1,530
  • Joined: 08-April 09

Re: Populate treeView from XML data file

Posted 02 May 2013 - 02:44 AM

First you need to populate the XML nodes you want to display and then use that to populate the treeview

See what you can do with this

This post has been edited by Michael26: 02 May 2013 - 02:47 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1