'create empty string Dim thecsvfile As String = String.Empty 'get the column headers For Each column As DataGridViewColumn In Datagrid.Columns thecsvfile = thecsvfile & column.HeaderText & "," Next 'trim the last comma thecsvfile = thecsvfile.TrimEnd(",") 'Add the line to the output thecsvfile = thecsvfile & vbCr & vbLf 'get the rows For Each row As DataGridViewRow In Datagrid.Rows 'get the cells For Each cell As DataGridViewCell In row.Cells thecsvfile = thecsvfile & cell.FormattedValue.replace(",", "") & "," Next 'trim the last comma thecsvfile = thecsvfile.TrimEnd(",") 'Add the line to the output thecsvfile = thecsvfile & vbCr & vbLf Next 'write the file My.Computer.FileSystem.WriteAllText("C:\Inventory System\Inventory Datasheet.csv", thecsvfile, False) End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)