The following code will write out a 'Quote Comma' style CSV file, in upper case, with one line for each row of cells in a DataGridView ... but in the reverse order to what's shown on screen

It takes values from the DataGridView1 component shown in blue, and writes it to the file location marked in red, so please change these to the names of your DataGridView and File location if you want to use this code in your own project. Just copy and paste the code below onto a button, and modify it as needed

Please rate the post if you find this useful. Cheers.

Code:
        Dim rows = From row As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
           Where Not row.IsNewRow _
           Select Array.ConvertAll(row.Cells.Cast(Of DataGridViewCell).ToArray, Function(c) If(c.Value IsNot Nothing, c.Value.ToString, ""))
        Dim r(rows.Count) As String
        Using sw As New IO.StreamWriter("U:\Test.imf")
            For rowNum As Integer = rows.Count - 1 To 0 Step -1
                r = rows(rowNum)
                'Write a double quotation mark as the first character of the line.
                sw.Write("""")
                'Uppercase and join the strings together into a quote comma CSV format before writing them to the file.
                Dim uppercaseit As String = Nothing
                uppercaseit = String.Join(""",""", r)
                uppercaseit = uppercaseit.ToUpper()
                sw.Write(uppercaseit)
                'Write a double quotation mark as the last character of the line, and finish with a carriage return.
                sw.WriteLine("""")
            Next
            sw.Close()
        End Using