Im having a problem where, if I select multiple DataGridView rows, all the information is placed into one line of the .csv file, this is giving me issues when trying to load the file back up.
Instead of having to select and saving each row individually (They are selected so they write to another file), how can I change the code below, so that for each selected row, each row is written onto another line.
What I have tried:
Private Sub btnToSession_Click(sender As Object, e As EventArgs) Handles btnToSession.Click
'PURPOSE: Write only selected DataGridView row to Session.csv
Dim StrExport As String = ""
For Each C As DataGridViewColumn In dataGVGeneral.Columns
StrExport &= "" & C.HeaderText & ","
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
'Only the row which is selected will be writen
For Each R As DataGridViewRow In dataGVGeneral.Rows
If R.Selected = True Then
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
StrExport &= "" & C.Value.ToString & ","
Else
StrExport &= "" & "" & ","
End If
Next
Else
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
End If
Next
'ROLE: Given ({filePath}, False)- allows for the file to be completely overwritten with new data.
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("E:\SAT\Work.io\Work.io\bin\Debug\Session.csv", False)
tw.Write(StrExport)
tw.Close()
End Sub