title: Export Fields that are Visible Equals to True in DataGridView
body: <p>I found this post about <a href="https://stackoverflow.com/questions/6686852/datagridview-to-csv-file">DataGridView to CSV File</a> and I am wondering if someone knows how to export fields that are only Visible = True? </p>
  
  <pre><code>Private Sub ExportCSVButton_Click(sender As Object, e As EventArgs) Handles ExportCSVButton.Click
          Dim headers = (From header As DataGridViewColumn In PadGridView.Columns.Cast(Of DataGridViewColumn)()
                         Select header.HeaderText).ToArray
          Dim rows = From row As DataGridViewRow In PadGridView.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, ""))
          Using sw As New IO.StreamWriter("export.csv")
              sw.WriteLine(String.Join(",", headers))
              For Each r In rows
                  sw.WriteLine(String.Join(",", r))
              Next
          End Using
          Process.Start("export.csv")
  End Sub
  </code></pre>