I have been trying to figure out how to get csvhelper to write the data that is in my datagridview. The datgridview is populated by the following.
First 3 are populated from a csv file with a class that has the csvhelper attributes to grab certiam columns from the csv file.
Then the rest of the datagridview is done like so.
And with me using what I have don I only get what is listed in the "new WriteCsvschedule { EmpName = "1", EmpPayrollID = "2" }," line only but I need all the data that is in the datagridview to be saved to a new csv file.
Any help on what I did wrong and to fix this is very much appreciated.
First 3 are populated from a csv file with a class that has the csvhelper attributes to grab certiam columns from the csv file.
Then the rest of the datagridview is done like so.
datagridview columns:
DataGridViewComboBoxColumn dgvCmb = new DataGridViewComboBoxColumn();
dgvCmb.HeaderText = "Mon OUT";
dgvCmb.Items.Add("");
dgvCmb.Items.Add("5:00a");
And with me using what I have don I only get what is listed in the "new WriteCsvschedule { EmpName = "1", EmpPayrollID = "2" }," line only but I need all the data that is in the datagridview to be saved to a new csv file.
Any help on what I did wrong and to fix this is very much appreciated.
Datagrid save code:
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = @"c:\rcs\schedule\";
saveFileDialog1.Title = "Save Schedule";
saveFileDialog1.DefaultExt = "txt";
saveFileDialog1.Filter = "CSV files (*.csv)|*.csv|csv Files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = saveFileDialog1.FileName;
}
var records = new List<WriteCsvschedule>
{
new WriteCsvschedule { EmpName = "1", EmpPayrollID = "2" },
};
using (var writer = new StreamWriter(saveFileDialog1.FileName))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(records);
}
EmpDataGrid.DataSource = records;
}