title: Import .txt to DataGridView (14 Columns separated by Space) VB.NET
body: <p>I need to import a .txt file into DataGridView where each column is separated by a space, but the problem lies in the last column. The last column contains spaces that shouldn't be evaluated as a "Split" (See Below).</p>
  
  <blockquote>
    <p><code>' 1    2    3      4    5   6   7     8      9      10     11      12      13     14
    SAT 0901 133000 1330 0002 002 003 000030 000000 00000000 000 00000C174BB 0000 This One</code></p>
  </blockquote>
  
  <pre><code>Private Sub ImpData(ByRef selectedFile As String)
      Dim dt As New DataTable
      For d = 1 To 14
          dt.Columns.Add(d, GetType(String))
      Next
      Dim lines = IO.File.ReadAllLines(selectedFile)
      Dim colCount = 14
  
      For Each line In lines
          Dim objFields = From field In line.Split(" "c)
                          Select field
          Dim newRow = dt.Rows.Add()
          newRow.ItemArray = objFields.ToArray()
      Next
      DataGridView1.DataSource = dt
  
  End Sub
  
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButton1.Click
  
      Dim selectedfile As String = ""
      OpenFileDialog1.ShowDialog()
      selectedfile = Path.GetFullPath(OpenFileDialog1.FileName)
      txtTEST1.Text = selectedfile
      ImpData(selectedfile)
  End Sub
  </code></pre>
  
  <p>"Input array is longer than the number of columns in this table." Is the error being thrown because of the Last Column of each Row. Any help would be greatly appreciated. Thanks</p>