1
這是我的程序的當前剪輯,因爲它是,datagridview斷開連接到數據表,如果我更改dataviewgrid上的任何東西,它不會反映在數據表中...我怎樣才能使它這樣datagridview上的任何編輯都可以反映到至少數據表中?c#Datagridview bindingsource
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;
嘿,我擺脫了datatables,而是使用列表綁定datagridview.source = list ...但是當我運行datagridview,它不允許我改變任何東西,即使我已經有了dgv.readonly = false – Magikarp 2012-04-01 16:35:20
在這種情況下,請使用BindingList代替:http://msdn.microsoft.com/en-us/library/ms132679.aspx – Maciej 2012-04-01 17:54:17
我做了,但綁定列表仍然不會讓我編輯datagridview中的值:/做到這一點現在需要一個actionevent? – Magikarp 2012-04-01 20:41:54