Hi
I am trying to export the contents of a datagridview to a text file but I only want to see the data that is visible. I have hidden certain non important columns which I do not want to export.
Please could someone help me modify the code accordingly.
Private Sub buttonSave_Click(sender As Object, e As EventArgs)
Dim filePath As String = Me.TextBox1.Text
Dim delimiter As String = ";"
Dim sb As New StringBuilder()
'create columnNames:
For i As Integer = 0 To dataGridView1.Rows.Count - 1
Dim array As String() = New String(dataGridView1.Columns.Count - 1) {}
If i.Equals(0) Then
'get column header text from all columns:
For j As Integer = 0 To dataGridView1.Columns.Count - 1
array(j) = dataGridView1.Columns(j).HeaderText
Next
sb.AppendLine([String].Join(delimiter, array))
End If
'get values from columns for specific row (row[i]):
For j As Integer = 0 To dataGridView1.Columns.Count - 1
If Not dataGridView1.Rows(i).IsNewRow Then
array(j) = dataGridView1(j, i).Value.ToString()
End If
Next
If Not dataGridView1.Rows(i).IsNewRow Then
sb.AppendLine([String].Join(delimiter, array))
End If
Next
File.WriteAllText(filePath, sb.ToString())
End Sub