Hope it will help you:
Dim sb As New System.Text.StringBuilder
'output column names
sb.AppendLine(String.Format("{0};{1};{2}", Me.DataGridView.Columns(0).Name.ToString, Me.DataGridView.Columns(1).Name.ToString, Me.DataGridView.Columns(2).Name.ToString))
' output values
For Each dr As DataGridViewRow In Me.DataGridView.Rows
If dr.Cells(0).Value IsNot Nothing AndAlso dr.Cells(1).Value IsNot Nothing AndAlso dr.Cells(2).Value IsNot Nothing Then
sb.AppendLine(String.Format("{0};{1};{2}", dr.Cells(0).Value.ToString, dr.Cells(1).Value.ToString, dr.Cells(2).Value.ToString))
End If
Next
My.Computer.FileSystem.WriteAllText("C:\Test.txt", sb.ToString, False)