title: Adding List<string> to DataTable
body: <p>I created a class library and I am trying to add data from a <code>List&lt;string[]&gt;</code> to a DataGridView.</p>
  <p>The string is in the format as follows:</p>
  <blockquote>
  <p>&quot;Test, 1^Glucose^10/24/2013 10:00;Test, 2^BUN^10/25/2013 11:00;Test, 3^BUN^10/25/2013 11:00&quot;</p>
  </blockquote>
  <p>I am passing the string from another program. I then an making it into a list and then trying to add it to the <code>DataTable</code> but no such luck. I created the datagridview with four columns.</p>
  <blockquote>
  <p>Selected - Checkbox</p>
  <p>Patient Name - String</p>
  <p>Order Name - String</p>
  <p>Order Date - String</p>
  <p>Reason - Combo Box</p>
  </blockquote>
  <p>I am getting an error:</p>
  <blockquote>
  <p>the list is greater than the number of columns.</p>
  </blockquote>
  <p><strong>Note</strong>: I can make the string anyway I want before passing to this program so if I need to do something with the string before passing it to the program, please let me know. Is there an easier way?</p>
  <p>I just want the data to display and I will work on the rest of it.</p>
  <p>Any help would be appreciated.</p>
  <p>This is my code:</p>
  <pre><code>public partial class RenewOrders : Form
  {
      public static string strMLMPatientData = string.Empty;
  
      public RenewOrders(string all_patient_data)
      {
          InitializeComponent();
          strMLMPatientData = &quot;Test, 1^Glucose^10/24/2013 10:00;Test, 2^BUN^10/25/2013 11:00;Test, 3^BUN^10/25/2013 11:00&quot;
      }
  
      private void RenewOrders_Load(object sender, EventArgs e)
      {    
          this.ConvertStringToList(strMLMPatientData);
      }
  
      private void ConvertStringToList(string strMLMPatientData)
      {
          var patient_list = strMLMPatientData.Split(';').Select(x =&gt; x.Split('^')).ToList();
          DataTable dtTable = ConvertListToDataTable(patient_list);
          dataGridView1.DataSource = dtTable;
      }
  
      // Convert to DataTable.
      static DataTable ConvertListToDataTable(List&lt;string[]&gt; patient_list)
      {
          // New table.
          DataTable dtTable = new DataTable();
  
          dtTable.Columns.Add(&quot;Name&quot;, typeof(string));
          dtTable.Columns.Add(&quot;Order Name&quot;, typeof(string));
          dtTable.Columns.Add(&quot;Order Date/Time&quot;, typeof(string));
          
          foreach (var row in patient_list)
          {
              table.Rows.Add(row);
          }
  
          return dtTable;
      }
  }
  </code></pre>