Im using a CSV to load data and save data from the DataGridView I have in a form. I would now like it so with a button click event I can send a row checked via the checkbox column on the DataGridView, to another dataGridView which is hosted in another form.
If it helps, here is the load im using to load and save the DataGridView contents.
What I have tried:
Private Sub btnLoadDGVGeneral_Click(sender As Object, e As EventArgs) Handles btnLoadDGVGeneral.Click
' PURPOSE: Load CSV file containing tasks into DataGridView
' Clearing DGV Rows allows for Tasks to not double up when rebooting the program
dataGVGeneral.Rows.Clear()
'New Variable: fname, represents File Path of CSV as String
Dim fname As String = "E:\SAT\Work.io\Work.io\bin\Debug\ListofTasks.csv"
Dim reader As New StreamReader(fname, Encoding.Default)
Dim sline As String = ""
Dim colsexpected As Integer = 7
Dim r As Integer = 0
'StreamReader will the file Line by Line, and add it to the variable sline
'First sline statement is Out of Loop, as first line of CSV contains headings to what each figure represents in a line.
sline = reader.ReadLine
Do
'Now sline will read the 2nd line and so forth
sline = reader.ReadLine
'If no value is found on that line of the CSV file (at the end), then the loop will exit
If sline Is Nothing Then Exit Do
'Details is as a variable, which when called upon, places each value into different columns for that row
Dim details() As String = sline.Split(",")
dataGVGeneral.Rows.Add()
For i As Integer = 0 To 6
dataGVGeneral.Rows(r).Cells(i).Value = details(i)
Next
'Increments value of "r" by 1, meaning next line of CSV will be added to the next row.
Dim v As Integer = r + 1
r = v
Loop
reader.Close()
End Sub
Private Sub btnSaveGeneralDGV_Click(sender As Object, e As EventArgs) Handles btnSaveGeneralDGV.Click
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
For Each R As DataGridViewRow In dataGVGeneral.Rows
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
StrExport &= """" & C.Value.ToString & ""","
Else
StrExport &= """" & "" & ""","
End If
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
Next
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("E:\SAT\Work.io\Work.io\bin\Debug\ListofTasks.csv", False)
tw.Write(StrExport)
tw.Close()
End Sub