This is a current clip of my program, as it is, the datagridview is disconnected to the datatable such that if I change anything on the dataviewgrid, it wont reflect in the datatable… How can I make it so that any edits on the datagridview can be reflected to atleast the datatable?
OpenFileDialog OFD = new OpenFileDialog();
OFD.Title = "CSV File";
OFD.Filter = "Spreadsheet | *.csv";
OFD.ShowDialog();
FileHelperEngine engine = new FileHelperEngine(typeof(csv_SeatingPlan));
try
{
csv_SeatingPlan[] container = engine.ReadFile(OFD.FileName) as csv_SeatingPlan[];
CSV_Seating_Plan = new List<csv_SeatingPlan>(container);
DataTable DT_student_Records = new DataTable();
DT_student_Records.Columns.Add("Exam_Period", typeof(string));
DT_student_Records.Columns.Add("Exam_Code", typeof(string));
DT_student_Records.Columns.Add("Student_ID", typeof(string));
DT_student_Records.Columns.Add("Student_Name", typeof(string));
DT_student_Records.Columns.Add("Candidate_Number", typeof(string));
foreach (csv_SeatingPlan row in CSV_Seating_Plan)
{
DT_student_Records.Rows.Add(row.examperiod, row.exam_Code, row.id_Student, row.name_Student, row.candidatenum_Student);
}
DT_student_Records.DefaultView.Sort = "Candidate_Number ASC";
this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 11);
//bindingCSVSP.DataSource = DT_student_Records;
this.dataGridView1.DataSource = DT_student_Records;
In order to propagate your changes to the underlying data source (in your case the table), you should use the BindingSource object. An example of how to do this is at the bottom of the linked page.