Results 1 to 4 of 4

Thread: Loading CSV file into DataGridView missing a row | SOLVED

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Loading CSV file into DataGridView missing a row | SOLVED

    Hello! I am trying to load in a CSV file into DataGridView and it works but I am missing one row. I save 5 rows of data and I only get 4 in return. Here is the code(I am still trying to learn and do so by asking questions and reading about stuff):

    Code:
     Dim fName As String = ""
            OpenFileDialog1.InitialDirectory = "c:\"
            OpenFileDialog1.Filter = "CSV files (*.csv)|*.CSV"
            OpenFileDialog1.FilterIndex = 2
            OpenFileDialog1.RestoreDirectory = True
            OpenFileDialog1.ShowDialog()
            fName = OpenFileDialog1.FileName
            Dim TextLine As String = ""
            If IO.File.Exists(fName) Then
                Dim Contents = IO.File.ReadAllLines(fName).ToList
    
                Contents.RemoveAt(0)
                Contents.RemoveAt(Contents.Count - 1)
                Contents.RemoveAt(Contents.Count - 1)
    
                For x As Integer = 0 To Contents.Count - 1
                    Contents(x) = Contents(x).Replace(",,,", ",").Replace(",,", ",")
                    Contents(x) = Contents(x).Substring(0, Contents(x).Count - 1)
                    Dim RowItem = Contents(x).Split(","c)
                    DataGridView1.Rows.Add(RowItem)
                Next
            End If
    Thanks in Advance!
    Last edited by Dragnorian; May 23rd, 2017 at 01:14 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width