title: XML file is able to read but i am stuck trying to get the class correct so I can display selected Elements in DataGridView1
body: <p>I'm creating a new program which will take info from multiple Xml files and compare the data returning errors if outside of certain parameters. The program runs with no errors but I am lost with how to display the info from certain Elements and Attributes into my dataGridView. I might prefer to write each Element or Attribute to individual text boxes.</p>
  
  <p>Here is the code currently working for my other XML files but the attributes and descendants for this one are slightly different, I need to get the Val="" attributes from TestResult/Data/mList Val=""</p>
  
  <pre><code>        DataTable dt10 = new DataTable();
          dt10.Columns.Add("model", typeof(string));
          dt10.Columns.Add("serial number", typeof(string));
          dt10.Columns.Add("fw version", typeof(string));
          dt10.Columns.Add("system", typeof(string));
          dt10.Columns.Add("test plan", typeof(string));
          dt10.Columns.Add("test date", typeof(DateTime));
          dt10.Columns.Add("test start time", typeof(DateTime));
  
          XDocument docrtnref = XDocument.Load(ofdRTNREF.FileName);
          XElement root = docrtnref.Root;
          XElement header = root.Element("Header");
          XElement testdata = root.Element("TestData");
  
          string model = (string)header.Element("model");
          string sn = (string)header.Element("serialNumber");
          string fwVersion = (string)header.Element("fwVersion");
          string system = (string)header.Element("system");
          string testPlan = (string)header.Element("testPlan");
          DateTime testDate = (DateTime)header.Element("testDate");
          TimeSpan testTime = DateTime.ParseExact((string)header.Element("testTime"), "HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).TimeOfDay;
          testDate = testDate.Add(testTime);
          DateTime testStartTime = (DateTime)header.Element("testStartTime");
  
  
  
          dt10.Rows.Add(new object[] {
              model, sn, fwVersion, system,testPlan, testDate, testStartTime,
          });
  
          dataGridView10.DataSource = dt10;
  
          DataTable dt9 = new DataTable();
          dt9.Columns.Add("Type", typeof(string));
          dt9.Columns.Add("cID", typeof(int));
          dt9.Columns.Add("mID", typeof(decimal));
  
  
          XElement data = root.Descendants("Data").FirstOrDefault();
  
          foreach (XElement ch in data.Elements("CH")) //No longer in this xml
          {
              int cID = (int)ch.Attribute("cID"); //No longer in this xml
              foreach (XElement meas in ch.Descendants("Meas"))//this would now be data.Descendants
              {
                  decimal? val = (string)meas.Attribute("Val") == string.Empty ? null : (decimal?)meas.Attribute("Val");
  
                  dt9.Rows.Add(new object[] { "Meas", cID, val });
              }
              XElement subData = ch.Descendants("Data").FirstOrDefault();
              if (subData != null)
              {
                  foreach (XElement mList in subData.Descendants("mList"))
                  {
                      string val = (string)mList.Attribute("Val");
                      decimal? numVal = null;
                      switch (val)
                      {
                          case "True":
                              numVal = 1;
                              break;
                          case "False":
                              numVal = 0;
                              break;
                          default:
                              numVal = val == null ? null : val == string.Empty ? null : (decimal?)decimal.Parse(val);
                              break;
  
                      }
  
                      dt9.Rows.Add(new object[] { "Mlist", cID, numVal });
                  }
              }
  
          }
  
          dataGridView9.DataSource = dt9;
  </code></pre>
  
  <p>in other videos on YouTube videos this  displays new tables on DataGridView1 but I just have nothing happen, No Errors just selects the Xml and then nothing.</p>
  
  <p>Here is the Xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;SunriseDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;TestData&gt;
      &lt;type&gt;Sweep&lt;/type&gt;
      &lt;subTest&gt;
        &lt;SWEEP&gt;
          &lt;Markers&gt;
            &lt;SavedSweepMarker&gt;
              &lt;Summary&gt;
                &lt;Setup mID="10240" lID="1999" Unit="0" Sto="4" Val="0" /&gt;
                &lt;Setup mID="10241" lID="1999" Unit="4" Sto="5" Val="98000000" /&gt;
                &lt;Setup mID="10242" lID="1999" Unit="2" Sto="7" Val="0" /&gt;
              &lt;/Summary&gt;
            &lt;/SavedSweepMarker&gt;
            &lt;SavedSweepMarker&gt;
              &lt;Summary&gt;
                &lt;Setup mID="10240" lID="1999" Unit="0" Sto="4" Val="0" /&gt;
                &lt;Setup mID="10241" lID="1999" Unit="4" Sto="5" Val="743000000" /&gt;
                &lt;Setup mID="10242" lID="1999" Unit="2" Sto="7" Val="0" /&gt;
              &lt;/Summary&gt;
            &lt;/SavedSweepMarker&gt;
             &lt;SavedSweepMarker&gt;
              &lt;Summary&gt;
                &lt;Setup mID="10240" lID="1999" Unit="0" Sto="4" Val="1" /&gt;
                &lt;Setup mID="10241" lID="1999" Unit="4" Sto="5" Val="0" /&gt;
                &lt;Setup mID="10242" lID="1999" Unit="2" Sto="7" Val="2" /&gt;
              &lt;/Summary&gt;
            &lt;/SavedSweepMarker&gt;
            &lt;SavedSweepMarker&gt;
              &lt;Summary&gt;
                &lt;Setup mID="10240" lID="1999" Unit="0" Sto="4" Val="1" /&gt;
                &lt;Setup mID="10241" lID="1999" Unit="4" Sto="5" Val="0" /&gt;
                &lt;Setup mID="10242" lID="1999" Unit="2" Sto="7" Val="-2" /&gt;
              &lt;/Summary&gt;
            &lt;/SavedSweepMarker&gt;
          &lt;/Markers&gt;
          &lt;GuardTable&gt;
            &lt;Data&gt;
              &lt;mList mID="10220" lID="1999" Unit="4" Sto="8" Val="83000000" /&gt;
              &lt;mList mID="10221" lID="1999" Unit="4" Sto="8" Val="873000000" /&gt;
              &lt;mList mID="10223" lID="1999" Unit="0" Sto="8" Val="96" /&gt;
              &lt;mList mID="10222" lID="1999" Unit="9" Sto="8" Val="0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0" /&gt;
              &lt;mList mID="10224" lID="1999" Unit="4" Sto="8" Val="87000000 93000000 98000000 103000000 111000000 119000000 125500000 132000000 140000000 152000000 160000000 168000000 175500000 183000000 191000000 199000000 207000000 215000000 223000000 231000000 239000000 247000000 255000000 263000000 271000000 279000000 287000000 295000000 303000000 311000000 319000000 327000000 335000000 343000000 351000000 359000000 367000000 375000000 383000000 391000000 399000000 407000000 415000000 427250000 432000000 438000000 446000000 454000000 462000000 470000000 478000000 486000000 494000000 510000000 534000000 557000000 571000000 578000000 586000000 594000000 602000000 610000000 618000000 626000000 634000000 642000000 650000000 658000000 666000000 674000000 682000000 690000000 698000000 706000000 714000000 722000000 730000000 738000000 743000000 747000000 754000000 762000000 770000000 778000000 786000000 794000000 802000000 810000000 818000000 826000000 834000000 842000000 850000000 858000000 863500000 867500000" /&gt;
              &lt;mList mID="10225" lID="1999" Unit="4" Sto="8" Val="2000000 4000000 1000000 4000000 4000000 4000000 2500000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 1000000 500000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 12000000 12000000 11000000 3000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 1000000 3000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 4000000 1500000 2500000" /&gt;
            &lt;/Data&gt;
          &lt;/GuardTable&gt;
          &lt;TestResult&gt;
            &lt;Data&gt;
              &lt;mList mID="10206" lID="1999" Unit="0" Sto="8" Val="1" /&gt;
              &lt;mList mID="10212" lID="1701" Unit="2" Sto="8" Val="8.03" /&gt;
              &lt;mList mID="10213" lID="1702" Unit="2" Sto="8" Val="18.69" /&gt;
              &lt;mList mID="10202" lID="1703" Unit="1" Sto="8" Val="10.61" /&gt;
              &lt;mList mID="10203" lID="1704" Unit="1" Sto="8" Val="15.05355" /&gt;
              &lt;mList mID="10207" lID="1999" Unit="0" Sto="8" Val="401" /&gt;
              &lt;mList mID="10201" lID="1999" Unit="4" Sto="8" Val="83000000 85000000 87000000 89000000 93000000 93000000 97000000 98000000 98000000 103000000 103000000 107000000 111000000 111000000 111000000 115000000 119000000 119000000 119000000 123000000 125500000 125500000 125500000 132000000 132000000 132000000 136000000 140000000 140000000 140000000 144000000 144220000 146200000 148000000 152000000 152000000 156000000 160000000 160000000 160000000 164000000 168000000 168000000 168000000 168000000 168000000 175500000 175500000 175500000 175500000 183000000 183000000 187000000 191000000 191000000 191000000 195000000 199000000 199000000 199000000 203000000 207000000 207000000 207000000 211000000 215000000 215000000 215000000 219000000 223000000 223000000 223000000 227000000 231000000 231000000 231000000 235000000 239000000 239000000 239000000 243000000 247000000 247000000 247000000 251000000 255000000 255000000 255000000 259000000 263000000 263000000 263000000 267000000 271000000 271000000 271000000 275000000 279000000 279000000 279000000 283000000 287000000 287000000 287000000 291000000 295000000 295000000 295000000 299000000 303000000 303000000 303000000 307000000 311000000 311000000 311000000 315000000 319000000 319000000 319000000 319000000 323000000 327000000 327000000 327000000 331000000 335000000 335000000 335000000 339000000 343000000 343000000 343000000 347000000 351000000 351000000 351000000 355000000 359000000 359000000 359000000 363000000 367000000 367000000 367000000 371000000 375000000 375000000 375000000 379000000 383000000 383000000 383000000 387000000 391000000 391000000 391000000 395000000 399000000 399000000 399000000 403000000 407000000 407000000 407000000 411000000 415000000 415000000 415000000 415000000 419000000 420720000 422700000 424670000 427250000 428620000 431500000 432000000 438000000 438000000 438000000 442000000 446000000 446000000 446000000 450000000 454000000 454000000 454000000 458000000 462000000 462000000 462000000 466000000 470000000 470000000 470000000 474000000 478000000 478000000 478000000 482000000 486000000 486000000 486000000 490000000 494000000 494000000 494000000 498000000 510000000 510000000 510000000 510000000 510000000 510000000 510000000 510000000 510000000 510000000 510000000 522000000 534000000 534000000 534000000 534000000 534000000 534000000 534000000 534000000 534000000 534000000 534000000 546000000 557000000 557000000 557000000 557000000 557000000 557000000 557000000 557000000 557000000 557000000 557000000 568000000 571000000 571000000 574000000 578000000 578000000 578000000 582000000 586000000 586000000 586000000 590000000 594000000 594000000 594000000 598000000 602000000 602000000 602000000 606000000 610000000 610000000 610000000 614000000 618000000 618000000 618000000 622000000 626000000 626000000 626000000 630000000 634000000 634000000 634000000 638000000 642000000 642000000 642000000 646000000 650000000 650000000 650000000 654000000 658000000 658000000 658000000 662000000 666000000 666000000 666000000 670000000 674000000 674000000 674000000 678000000 682000000 682000000 682000000 686000000 690000000 690000000 690000000 694000000 698000000 698000000 698000000 702000000 706000000 706000000 706000000 710000000 714000000 714000000 714000000 714000000 718000000 722000000 722000000 722000000 726000000 730000000 730000000 730000000 734000000 738000000 738000000 738000000 742000000 743000000 747000000 747000000 750000000 754000000 754000000 754000000 758000000 762000000 762000000 762000000 766000000 770000000 770000000 770000000 774000000 778000000 778000000 778000000 782000000 786000000 786000000 786000000 790000000 794000000 794000000 794000000 798000000 802000000 802000000 802000000 806000000 810000000 810000000 810000000 814000000 818000000 818000000 818000000 822000000 826000000 826000000 826000000 830000000 834000000 834000000 834000000 838000000 842000000 842000000 842000000 846000000 850000000 850000000 850000000 854000000 858000000 858000000 858000000 862000000 863500000 863500000 867500000 867500000 870000000 871020000 873000000 98000000 743000000" /&gt;
              &lt;mList mID="10200" lID="1999" Unit="1" Sto="8" Val="-6.46 -6.28 -5.45 -5.45 -4.87 -4.87 -4.87 8.03 8.03 -4.94 -4.94 -4.94 -4.51 -4.51 -4.51 -4.51 -4.91 -4.91 -4.91 -4.91 -3.45 -3.45 -3.45 -3.45 -3.45 -3.45 -3.45 -3.56 -3.56 -3.56 -3.56 -4.3 -3.88 -4.17 -3.77 -3.77 -3.77 -4.23 -4.23 -4.23 -4.23 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.98 -3.63 -3.63 -3.63 -3.63 -3.71 -3.71 -3.71 -3.71 -3.77 -3.77 -3.77 -3.77 -3.87 -3.87 -3.87 -3.87 -3.73 -3.73 -3.73 -3.73 -3.7 -3.7 -3.7 -3.7 -2.67 -2.67 -2.67 -2.67 -2.96 -2.96 -2.96 -2.96 -2.79 -2.79 -2.79 -2.79 -2.61 -2.61 -2.61 -2.61 -0.75 -0.75 -0.75 -0.75 -3.07 -3.07 -3.07 -3.07 -2.71 -2.71 -2.71 -2.71 -2.4 -2.4 -2.4 -2.4 -2.26 -2.26 -2.26 -2.26 -1.8 -1.8 -1.8 -1.8 -0.86 -0.86 -0.86 -0.86 -0.86 -1.43 -1.43 -1.43 -1.43 -1.56 -1.56 -1.56 -1.56 -1.11 -1.11 -1.11 -1.11 -0.58 -0.58 -0.58 -0.58 3.16 3.16 3.16 3.16 -1.4 -1.4 -1.4 -1.4 0.77 0.77 0.77 0.77 -0.39 -0.39 -0.39 -0.39 -0.8 -0.8 -0.8 -0.8 2.05 2.05 2.05 2.05 1.26 1.26 1.26 1.26 1.37 1.37 1.37 1.37 1.37 1.39 11.26 1.45 1.29 1.29 1.69 5.93 5.93 5.93 5.93 5.93 3.59 3.59 3.59 3.59 3.74 3.74 3.74 3.74 4.03 4.03 4.03 4.03 1.35 1.35 1.35 1.35 2.1 2.1 2.1 2.1 3.18 3.18 3.18 3.18 2.7 2.7 2.7 2.7 5.14 5.14 5.14 5.14 5.14 5.14 5.14 5.14 5.14 5.14 5.14 5.14 5.77 5.77 5.77 5.77 5.77 5.77 5.77 5.77 5.77 5.77 5.77 5.77 4.73 4.73 4.73 4.73 4.73 4.73 4.73 4.73 4.73 4.73 4.73 4.73 4.12 4.12 4.12 5.72 5.72 5.72 5.72 5.24 5.24 5.24 5.24 6.63 6.63 6.63 6.63 7.52 7.52 7.52 7.52 3.79 3.79 3.79 3.79 7.45 7.45 7.45 7.45 7.42 7.42 7.42 7.42 5.79 5.79 5.79 5.79 6.29 6.29 6.29 6.29 5.91 5.91 5.91 5.91 6.28 6.28 6.28 6.28 6.77 6.77 6.77 6.77 6.44 6.44 6.44 6.44 6.1 6.1 6.1 6.1 7.48 7.48 7.48 7.48 6.63 6.63 6.63 6.63 7.6 7.6 7.6 7.6 6.52 6.52 6.52 6.52 6.52 5.07 5.07 5.07 5.07 4.9 4.9 4.9 4.9 3.57 3.57 3.57 3.57 18.64 2.33 2.33 2.33 3.75 3.75 3.75 3.75 2.96 2.96 2.96 2.96 4.56 4.56 4.56 4.56 4.59 4.59 4.59 4.59 3.98 3.98 3.98 3.98 3.17 3.17 3.17 3.17 3.82 3.82 3.82 3.82 3.62 3.62 3.62 3.62 2.92 2.92 2.92 2.92 3.42 3.42 3.42 3.42 2.63 2.63 2.63 2.63 3.7 3.7 3.7 3.7 3 3 3 3 2 2 2 2 17.74 17.74 -0.45 -0.45 -0.45 -0.38 -0.38 8.03 18.69" /&gt;
              &lt;mList mID="10208" lID="1999" Unit="2" Sto="8" Val="3700" /&gt;
              &lt;mList mID="10209" lID="1999" Unit="1" Sto="8" Val="0" /&gt;
              &lt;mList mID="10210" lID="1999" Unit="1" Sto="8" Val="" /&gt;
              &lt;mList mID="10211" lID="1999" Unit="0" Sto="8" /&gt;
              &lt;mList mID="10204" lID="1999" Unit="4" Sto="8" Val="98000000" /&gt;
              &lt;mList mID="10205" lID="1999" Unit="4" Sto="8" Val="743000000" /&gt;
              &lt;mList mID="10214" lID="1999" Unit="1" Sto="8" Val="0" /&gt;
              &lt;mList mID="10215" lID="1999" Unit="1" Sto="8" Val="0" /&gt;
              &lt;mList mID="10216" lID="1999" Unit="0" Sto="8" Val="0" /&gt;
              &lt;mList mID="10217" lID="1999" Unit="0" Sto="8" Val="0" /&gt;
              &lt;mList mID="10218" lID="1999" Unit="0" Sto="8" Val="0" /&gt;
            &lt;/Data&gt;
          &lt;/TestResult&gt;
        &lt;/SWEEP&gt;
      &lt;/subTest&gt;
    &lt;/TestData&gt;
  &lt;/SunriseDocument&gt;
  </code></pre>